to replace a exact word
Posted: Mon Nov 30, 2009 4:46 am
hi all i need to replace a word in a string with exact match, in php
eg:
search string=center
replace string=center_another
subject=center centertop centerright centerleft
these all will be dynamic values
then result should be
subject=center_another centertop centerright centerleft
hers is my code
<?php
$s="center center_top centerleft center.right centerbottom center-width centerheight";
$t="center";
$find="/".$t."?/";
$find_r="center";
$replace=$find_r."_another";
preg_replace($find,$replace,$s);
?>
thanks in advance
eg:
search string=center
replace string=center_another
subject=center centertop centerright centerleft
these all will be dynamic values
then result should be
subject=center_another centertop centerright centerleft
hers is my code
<?php
$s="center center_top centerleft center.right centerbottom center-width centerheight";
$t="center";
$find="/".$t."?/";
$find_r="center";
$replace=$find_r."_another";
preg_replace($find,$replace,$s);
?>
thanks in advance