hosted by liquidweb


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

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
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

Reply With Quote


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.
Reply With Quote
  #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 ?

Reply With Quote
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: 551
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.

Reply With Quote
  #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 With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
How to Create a Cultural Connection with Jeremy Gutsche of TrendHunter Web Hosting News 2013-02-06 13:45:48
Great Teams That Deliver Amazing Service Don't Just Happen Blog 2012-06-11 11:14:09
Web Host myhosting.com Updates Shared Hosting Plans Web Hosting News 2011-10-20 18:46:01
HostingCon Day 1 Blog 2011-08-08 22:53:21
Web Hosting Sales Techniques with Mike Zobitz of SingleHop Web Hosting News 2011-08-08 22:12:59


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?