Logo

String Replacer

Posted under » PHP on 01 April 2009

If you don't require regex, you should use str_replace to replace strings.

$link = str_replace("JScripts",'<a href="010.php">Javascript',$word);

In the above example, any occurence of "JScripts" in the string ($word) will be replaced by a link to "010.php".

However if regular expressions is needed use preg_replace.

$baong = "<option value=babi";
$pattern = "{<option value}";
$celeng = preg_replace($pattern, "<a href", $baong);

preg_replace() is sometimes known as ereg_replace()