How to replace % with html tag in PHP -
i have following code in php:
$fullstring = "a %sample% word go %here%"; and want replace % html tag (<span style='color:red'> , </span>). want after replacing:
$fullstring ="a <span style='color:red'>sample</span> word go <span style='color:red'>here</span>"; what should accomplish result using php function str_replace, preg_replace etc.? thanks.
you do....
$string = "a %sample% word go %here%"; echo preg_replace('~%(.*?)%~', '<span style="color:red">$1</span>', $string); that says replace between first % , next occurring % sign spans. () groups inside percents $1.
output:
a <span style="color:red">sample</span> word go <span style="color:red">here</span>