Re: search string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <weetat.yeo@xxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux