Allrigh!
I have a highlighting function that is suppose to highligh certain C# keywords. But when it comes to words like 'if', 'is', 'do' and other small words, they can be found in other words, such as infinity, nifty and doh, so I want to be able to find ONLY 'if', 'is', 'in', etc.
Problem is, this won't work:
CODE
$sumstr = preg_replace('#\bin\b#', '<span class="blueBold">in</span', $sumstr);
$sumstr = preg_replace('#\bif\b#', '<span class="blueBold">if</span', $sumstr);
$sumstr = preg_replace('#\bis\b#', '<span class="blueBold">is</span', $sumstr);
It will work for the first one, but the rest won't work, and I'll lose alot of blankspaces in the text.
And if I do this:
CODE
$var = '#\bif\b#';
$sumstr = preg_replace($var, '<span class="blueBold">'.$var.'</span', $sumstr);
the 'if' in the text will be blue, but will also be 'bifb'. So it it gets blue and bold, but somehow the b's are added!
This post has been edited by maffelu: 3 Oct, 2008 - 02:05 AM