Forum Moderators: coopster

Message Too Old, No Replies

Grab words out of a paragraph

what is the function I use?

         

wfernley

2:41 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey, this will probably be an easy question.

I have a paragraph of text but I need to highlight certain words. I will be implementing this in a search engine I have. I was curious what the function is for me to pick out words of a paragraph. Also, if you know how I can highlight these words that would be great too :)

Thanks in advance for your help!

Wes

coopster

3:05 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Using a regular expression [php.net] is one option. The preg_replace() [php.net] function seems a good solution here.

wfernley

5:28 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great Thank you for the reply coopster. I found that function doesn't take into account words starting with a capital letter. You can use the strtolower() function but then all the words would be in lowercase and you would lose all caps at the beginning of a sentence. Do you know anyway around this?

Thanks :)

dmorison

5:32 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can make your regular expression case insensitive with the /i modifier on the end.

coopster

5:33 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, you can use the i pattern modifier [php.net] to make the search case insensitive.

thanks dmorison :-)

wfernley

5:53 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great. Thanks again for the reply :)