I am obviously doing something completely wrong when it comes to preg_replace.
Say I have a string of text,
"Silence is golden until you are the one silenced." And I want to replace "Silence" with "Silence" but not replace the silence in silenced.
Here is the code I have in place:
$q = "Silence is golden until you are the one silenced.";
$card = "Silence";
$pattern = '/\b'.$card.'\b/i';
$q = preg_replace($pattern,'<strong>'.$card.'</strong>',$q);
This is failing and setting $q = ""
What am I doing wrong?
Problem solved. In the actual code I am iterating over an array of items to preg_replace and just applying preg_replace without first testing using preg_match.
精彩评论