I have a sentence in the DB for example:
His $name$ is $Luis$
Now, I want to replace the $..$ in tags (< b >), for something like:
His <b>name</b> is <b>Luis</b>
How can I do it with preg_replace? I tried to do simply:
$replace[0] = '<b>';
$replace[1] = '</b>';
preg_replace('/[$]/', $replace, $string);
But doesn't work.
preg_replace( '/\$(.*?)\$/', '<b>\1</b>', $string );
This will solve your problem:
$source = 'His $name$ is $Luis$';
$result = preg_replace('/\$(.*?)\$/', '<b>$1</b>', $source);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With