Solved

if i have a word and i want to see if it exist in a sentence how can i do that?

Posted on 2008-09-30
6
203 Views
Last Modified: 2012-05-05
if i have a word and i want to see if it exist in a sentence how can i do that?
lets say i want to search for the word "hall" in the sentence "the hall of fame in expert"
and please i dont want it using explode because i know how to do it using explode
0
Comment
Question by:mgtm3
  • 3
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22612111
can you explain why you don't want to use explode?
that will clarify in which direction any suggestions have to go.
0
 

Author Comment

by:mgtm3
ID: 22612150
beacuse i need something fast
i have a table that have 500,000 rows so i want to search in every row to find something(word)
and using explode i takes me 30-60 seconds to find it.
so becouse of that i want something better and faster
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22612172
>i have a table that have 500,000 rows
mysql? did you check out full-text index?
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Assisted Solution

by:lorenzodalcol
lorenzodalcol earned 100 total points
ID: 22612173
if you use mysql you can use fulltext search.

With PHP you can use strpos

<?php

$mystring = 'the hall of fame in expert';

$findme   = 'hall';

$pos = strpos($mystring, $findme);
 

// Note our use of ===.  Simply == would not work as expected

// because the position of 'a' was the 0th (first) character.

if ($pos === false) {

    echo "The string '$findme' was not found in the string '$mystring'";

} else {

    echo "The string '$findme' was found in the string '$mystring'";

    echo " and exists at position $pos";

}

?>

Open in new window

0
 

Author Comment

by:mgtm3
ID: 22612256
angell can you give me an example ?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 22612271
well, in the link I gave you there are plenty of examples...
http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
mysql> CREATE TABLE articles (

    ->   id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,

    ->   title VARCHAR(200),

    ->   body TEXT,

    ->   FULLTEXT (title,body)

    -> );

Query OK, 0 rows affected (0.00 sec)
 

mysql> INSERT INTO articles (title,body) VALUES

    -> ('MySQL Tutorial','DBMS stands for DataBase ...'),

    -> ('How To Use MySQL Well','After you went through a ...'),

    -> ('Optimizing MySQL','In this tutorial we will show ...'),

    -> ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),

    -> ('MySQL vs. YourSQL','In the following database comparison ...'),

    -> ('MySQL Security','When configured properly, MySQL ...');

Query OK, 6 rows affected (0.00 sec)

Records: 6  Duplicates: 0  Warnings: 0
 

mysql> SELECT * FROM articles

    -> WHERE MATCH (title,body) AGAINST ('database');

+----+-------------------+------------------------------------------+

| id | title             | body                                     |

+----+-------------------+------------------------------------------+

|  5 | MySQL vs. YourSQL | In the following database comparison ... |

|  1 | MySQL Tutorial    | DBMS stands for DataBase ...             |

+----+-------------------+------------------------------------------+

2 rows in set (0.00 sec)

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now