Jump to content

how can find some of words and replace it ..


abosami

Recommended Posts

Hi ,,

my frineds , how r u ?

 

I have this article in my script:

<<WordPress>> widgets are the dynamic objects which eases the customization of the content on <<sidebars>> and widgetized <<footers>>. <<Widgets>> allows drag-n-drop interface in the Dashboard <<admin panel>>, for easy <<management>>.

I want from the script , search about any word have <<..>> and replace it by: <a href="the word.php"> the word <a/>

for examle :

when the script find this word: <<Hello World>> , directly update it and replace

PHP Code:

<a href="hello-world.php"> Hello world </a>

how can work it ..

 

thank you very much for helping me ..

 

^_^

 

 

Link to comment
Share on other sites

This can be accomplished using regular expressions and preg_replace_callback. Like this:

 

$text =<<<TEXT
<<WordPress>> widgets are the dynamic objects which eases the customization of the content on <<sidebars>> and widgetized <<footers>>. <<Widgets>> allows drag-n-drop interface in the Dashboard <<admin panel>>, for easy <<management>>.
TEXT;

$text = preg_replace_callback(
'~<<([^>]+)>>~',
create_function(
	'$match',
	'return "<a href=\"" . str_replace(" ", "-", $match[1]) . ".php\">" . $match[1] . "</a>";'
),
$text
);

echo $text;

 

Or using anonymous functions if you have PHP 5.3.0+ installed:

 

$text =<<<TEXT
<<WordPress>> widgets are the dynamic objects which eases the customization of the content on <<sidebars>> and widgetized <<footers>>. <<Widgets>> allows drag-n-drop interface in the Dashboard <<admin panel>>, for easy <<management>>.
TEXT;

$text = preg_replace_callback(
'~<<([^>]+)>>~',
function($match) {
	return "<a href=\"" . str_replace(" ", "-", $match[1]) . ".php\">" . $match[1] . "</a>";
},
$text
);

echo $text;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.