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 ..

 

^_^

 

 

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.