7, September 2008

Search for list of words in a string - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Search for list of words in a string
« previous next »
Pages: [1] Print

Author Topic: Search for list of words in a string  (Read 537 times)
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« on: Dec 05, 2005, 09:11:15 AM »

I have a list of words and their definitions in a db table. Now I want to check to see if any of those words appear in a string, probably only a paragraph long.

What is the best way to search through the string for those words? I guess putting the words into an array and then checking if any one of those words are in the string. I just want to find the fastest method and the one that is the least cpu intensive.


Last blog : Site of the Month - August 2007
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #1 on: Dec 05, 2005, 12:03:01 PM »

That propably depends on how many words you have in your paragraphs.

If you are going to do something like a thesaurus where people get the mouse over a word and see the meaning of the word, let me tell you the logic I used in a simmilar script. Of course this logic is suitable only if you have lots of words in your paragraphs, and in your db.

First I take the words in the paragraph, and split them by spaces. Then I create a query that search only for those words. Then from the db result, I do something like this :

Code:
<?php
foreach ( $words as word => $meaning )
{
   
$paragraph str_replace $word$meaning$paragraph );
}
?>


Hope this will help Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=929
Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Search for list of words in a string
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 07, 2008, 11:14:57 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.301
Total Topics: 7.479
Total Members: 3.904
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Brandon

35 Guests, 3 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.