28, May 2012

Search for list of words in a string - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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


Gimme all your cookies!!!


« on: Dec 05, 2005, 08: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 : Canonical URL Links / Tags
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Dec 05, 2005, 11:03:01 am »

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 or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=929
Bookmark this thread : Digg Del.icio.us Dzone more....

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?
May 28, 2012, 11:47:22 pm





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!






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