Re: [PHP] search string
You can use a regular expressions with a function called preg_match to find the values. For example, (Assuming your sql statement is $sql) preg_match(/(tbl_chassis.chasis_model LIKE \'\%[a-zA-Z0-9-]+\%\'/), $sql, $matches); That will return $matches[0] with the matched data. Similarly, preg_match(/(AND lower\(country\) = lower\(trim\(\'(\w+)\'\)\))/, $sql, $matches); does the same thing, again in $matches[0]. The full description of preg_match can be found here: http://us2.php.net/manual/en/function.preg-match.php On 7/20/06, weetat [EMAIL PROTECTED] wrote: Hi all , I am using php4.3.2,MYSQL and RedHat I have a sql text as shown below: SELECT DISTINCT(tbl_chassis.serial_no),tbl_chassis.host_name,tbl_chassis.chasis_model,tbl_chassis.country,tbl_chassis.city,tbl_chassis.building, tbl_chassis.other,tbl_chassis.status,tbl_chassis.chasis_eos,tbl_chassis.chasis_eol,tbl_chassis.chasis_user_field_1,tbl_chassis.chasis_user_field_2,tbl_chassis.chasis_user_field_3 from tbl_chassis tbl_chassis,tbl_card tbl_card WHERE tbl_chassis.serial_no = tbl_card.serial_no AND tbl_chassis.chasis_model LIKE '%WS-C5500%' AND lower(country) = lower(trim('Malaysia')) ORDER BY country,city,building,other I need to extract the tbl_chassis.chasis_model LIKE '%WS-C5500%' and lower(country) = lower(trim('Malaysia')) and join them to new string. Anyone have any suggestion how to do this? Thanks -weetat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] search string
Hi all , I am using php4.3.2,MYSQL and RedHat I have a sql text as shown below: SELECT DISTINCT(tbl_chassis.serial_no),tbl_chassis.host_name,tbl_chassis.chasis_model,tbl_chassis.country,tbl_chassis.city,tbl_chassis.building, tbl_chassis.other,tbl_chassis.status,tbl_chassis.chasis_eos,tbl_chassis.chasis_eol,tbl_chassis.chasis_user_field_1,tbl_chassis.chasis_user_field_2,tbl_chassis.chasis_user_field_3 from tbl_chassis tbl_chassis,tbl_card tbl_card WHERE tbl_chassis.serial_no = tbl_card.serial_no AND tbl_chassis.chasis_model LIKE '%WS-C5500%' AND lower(country) = lower(trim('Malaysia')) ORDER BY country,city,building,other I need to extract the tbl_chassis.chasis_model LIKE '%WS-C5500%' and lower(country) = lower(trim('Malaysia')) and join them to new string. Anyone have any suggestion how to do this? Thanks -weetat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] search string / query format
I'm going to create a search page that accepts input similar to places like Yahoo and Google. Example input would be: Keyword AND keyword2 Keyword -keyword2 +keyword3 keyword keyword2 -keyword3 Rather than reinvent things though, I'm wondering if anyone here happens to have a script or function that will handle that type of input. It would be great if someone already has a function that accepts the initial query, a table to query against, and a list of fields to query against, and returns the appropirate SQL statement. Also, I've heard that MySQL's indexing can support some of this, but I'm not sure how much. Thanks in advance for any pointers or info you might have on this. -Ed
Re: [PHP] search string / query format
Ed Lazor wrote: I'm going to create a search page that accepts input similar to places like Yahoo and Google. [snip] Also, I've heard that MySQL's indexing can support some of this, but I'm not sure how much. Using a FULLTEXT index and searching in BOOLEAN mode supports the type of search strings that you wrote. Consult thine manual!! (The MySQL one) ;) -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] search string / query format
Keyword AND keyword2 keyword keyword2 -keyword3 It doesn't support AND or OR but it does use - + * and others. Consult thine manual!! (The MySQL one) ;) http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html The problem is getting a FULLTEXT to sort by relevancy. This was a real pain, until our friend John W. showed me the error of my ways; (see below). MySQL The preceding example is a basic illustration showing how to use the MATCH() function MySQL where rows are returned in order of decreasing relevance I never did believe the examples helped me: http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html You will need something like this to make the operators display according to relevancy. This works: SELECT *,MATCH (field1,field2,field3) AGAINST ('Margaret Atwood' IN BOOLEAN MODE) AS relevancy FROM mytable WHERE MATCH (field1,field2,field3) AGAINST ('Margaret Atwood' IN BOOLEAN MODE) ORDER BY relevancy DESC; This does not sort by relevancy well at all: SELECT * (field1,field2,field3) FROM mytable AGAINST ('Margaret Atwood' IN BOOLEAN MODE); P.S. John W.: thanks for helping me on my post last week. I finally got this working. John John W. Holmes wrote: Ed Lazor wrote: I'm going to create a search page that accepts input similar to places like Yahoo and Google. [snip] Also, I've heard that MySQL's indexing can support some of this, but I'm not sure how much. Using a FULLTEXT index and searching in BOOLEAN mode supports the type of search strings that you wrote. Consult thine manual!! (The MySQL one) ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] search string / query format
-Original Message- I'm going to create a search page that accepts input similar to places like Yahoo and Google. [snip] Also, I've heard that MySQL's indexing can support some of this, but I'm not sure how much. Using a FULLTEXT index and searching in BOOLEAN mode supports the type of search strings that you wrote. Consult thine manual!! (The MySQL one) ;) *grin* Thanks John, I knew someone would know where I'd seen it hehe -Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] search string
What is the function to search a string? Basically, I want search a string (a url) to see if it has "www.yahoo.com" in it and if yes, tell the user their submission cannot be accepted. J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] search string
Hi Joseph, @ 12:08:46 PM on 4/15/2001, Joseph Bannon wrote: What is the function to search a string? Basically, I want search a string (a url) to see if it has "www.yahoo.com" in it and if yes, tell the user their submission cannot be accepted. ?php $string = 'www.yahoo.com'; print(strstr($string,'yahoo.com') ? 'Failed.' : 'Passes'); ? -Brian -- PGP is spoken here: 0xE4D0C7C8 Please, DO NOT carbon copy me on list replies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] search string
I think you want regular expressions... Try this on for size: $str = "http://www.yahoo.com/somedir/somepage.html"; if (preg_match("/www.yahoo.com/i", $str)) { print "Your submission cannot be accepted"; } else { print "You are good"; } If you want to read up on regular expressions: http://www.php.net/manual/en/ref.pcre.php (Faster than ereg) http://www.php.net/manual/en/ref.regex.php // Tobias Talltorp ""Joseph Bannon"" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What is the function to search a string? Basically, I want search a string (a url) to see if it has "www.yahoo.com" in it and if yes, tell the user their submission cannot be accepted. J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] search string
Even better, try strstr...it'll be faster than a regexp for a simple search of a string for another string. -jack - Original Message - From: "Tobias Talltorp" [EMAIL PROTECTED] Date: Sunday, April 15, 2001 7:20 pm Subject: Re: [PHP] search string I think you want regular expressions... Try this on for size: $str = "http://www.yahoo.com/somedir/somepage.html"; if (preg_match("/www.yahoo.com/i", $str)) { print "Your submission cannot be accepted"; } else { print "You are good"; } If you want to read up on regular expressions: http://www.php.net/manual/en/ref.pcre.php (Faster than ereg) http://www.php.net/manual/en/ref.regex.php // Tobias Talltorp ""Joseph Bannon"" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... What is the function to search a string? Basically, I want search a string (a url) to see if it has "www.yahoo.com" in it and if yes, tell the user their submission cannot be accepted. J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: php-list- [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: php-list- [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] search string
Hi Tobias, @ 7:20:00 PM on 4/15/2001, Tobias Talltorp wrote: I think you want regular expressions... Try this on for size: $str = "http://www.yahoo.com/somedir/somepage.html"; if (preg_match("/www.yahoo.com/i", $str)) { print "Your submission cannot be accepted"; } else { print "You are good"; } ... I doubt there is a need to use regular expressions just to find out of a string has yahoo.com in it. -Brian -- PGP is spoken here: 0xE4D0C7C8 Please, DO NOT carbon copy me on list replies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]