Reply to Re: [PHP] marking words bold

Your name:

Reply:


Posted by Philip Hallstrom on 05/11/05 19:47

> Hi there,
>
> I am trying to mark words inside a sentence bold. Problem is, if there is an
> overlap it does not work anymore.
> I am using this code: $t = str_replace($word, "<b>$word</b>", $text);
>
> For eample:
> Mark those words bold: adventure in singapore
> Text: My adventure flying to singapore
>
> The problem lays in the word "in". The code I use does produce following:
> <b>s<b>in</b>gapore</b>
> which of course does not work properly.
>
> Does anybody have a good sugestion on how to improve this?`

I don't have it in front of me, but if you use preg I believe you can do
something like:

preg_replace("/(\s)$word(\s)/", "\1<b>$word<\b>\2", $text);

or something like that. The "\s" matches whitespace..

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация