hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Highlight words (PHP)
Reply

Forum Jump

Highlight words (PHP)

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 12-13-2005, 09:20 AM
actionman actionman is offline
Newbie
 
Join Date: Jul 2005
Posts: 22

Highlight words (PHP)


hi,

I have a few ideas but i need something a lot better so please help.

I am trying to highlight all the words that match a given string.

for example.

i want something like this,
http://domain.com/highlight.php?url=...tring=blahblah

then it should search the yahoo.com's page and highlight all the "blahblah" words.

Any idea how should i do that or has it been coded before ?

thanks



Sponsored Links
  #2  
Old 12-14-2005, 01:15 AM
error404 error404 is offline
Web Hosting Master
 
Join Date: Dec 2004
Location: Canada
Posts: 1,076
A clumsy and naive way of doing it would be:
PHP Code:
$new preg_replace("/\b($word)\b/i""<span class='highlight'>\1</span>"$string); 
This is probably a bad idea on any sort of marked-up text, as it'll clobber parameter names and such as well. You need a state machine to fix that.

__________________
>> Keenan Tims
█▓▒░ I am currently looking for full-time work in the Vancouver area. Resume ░▒▓█
http://www.gotroot.ca/ | ktims@gotroot.ca | skype: keenan.tims


Last edited by error404; 12-14-2005 at 01:22 AM.
  #3  
Old 12-14-2005, 02:17 AM
actionman actionman is offline
Newbie
 
Join Date: Jul 2005
Posts: 22
thanks for the reply,

that's what i have in mind but how do you grab words from a given url and "highlight" them ?

Sponsored Links
  #4  
Old 12-14-2005, 09:14 AM
Dark Light Dark Light is offline
Community Guide
 
Join Date: Oct 2005
Location: UK
Posts: 552
Hello,

If you wanted to get the words from the url, such as 'highlight.php?highlight=word', you might try doing:

PHP Code:
$word $_GET[highlight]; 
Put that before the preg_replace(); that error404 wrote.
You might want to do some checks on that as-well.

I hope that helps , if that's not you wanted, I apoligise,
- Dark Light.

  #5  
Old 12-14-2005, 09:19 AM
error404 error404 is offline
Web Hosting Master
 
Join Date: Dec 2004
Location: Canada
Posts: 1,076
Note that the \1 in my code should be a double backslash (or $1 instead if you're using a non-archaic PHP version).

__________________
>> Keenan Tims
█▓▒░ I am currently looking for full-time work in the Vancouver area. Resume ░▒▓█
http://www.gotroot.ca/ | ktims@gotroot.ca | skype: keenan.tims

Reply

Related posts from TheWhir.com
Title Type Date Posted
EMEA Server Shipments and Revenue Start Recovery After 11 Brutal Quarters: Gartner Web Hosting News 2014-08-27 13:34:56
HostingCon 2014: The Art of Selling Space with Makiko Ara, Total Product Marketing Web Hosting News 2014-06-18 12:45:21
Communicating 21st-Century Hosting Terms to 20th-Century Clients Blog 2014-04-24 13:27:34
Nominet Seeks Feedback on Banning Offensive .UK Domain Registrations Web Hosting News 2013-09-13 15:25:36
How to Create a Cultural Connection with Jeremy Gutsche of TrendHunter Web Hosting News 2013-02-06 13:45:48


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?