PHP preg_match? preg_match_all? Help please?

alco19357

New member
I have a script which searches for strings that will be used for insert functions for XML databasing.

I'm using preg_match_all but am having errors.

Initial string to query:
insert into clothing/mens (item/size, item/price) values (XL, 49.99)


preg_match_all("/(\([^)]*)\)(.*)(\))/i", $insert, $values, PREG_SET_ORDER); // queries initial string

$return_preg = $values[0][0]; //returns only first part

preg_match_all("/(.*)(values)(.*)/i", $return_preg, $identifier, PREG_SET_ORDER); // returns only the field + string(values) + values



$fields_r = substr(trim($identifier[0][1]), 1, (strlen(trim($identifier[0][1]))-2)); // returns only field and removes the parenthesis

$values_r = substr(trim($identifier[0][3]), 1, (strlen(trim($identifier[0][3]))-2)); // returns only values and removes the parenthesis

$fields = explode(',', $fields_r); //gets individual field marker
$values = explode(',', $values_r); //gets individual value

This script works perfectly when I use only 1 field and 1 value. But when i add multiple values and fields (comma separated), I get the below output:

(item/size, item/price) values (fdas, dasf)(item/size, item/price) values (fdas, dasf)

What can I do to extract only: (item/size, item/price) values (fdas, dasf) from the initial string?

Thank you VERY MUCH!!!
Alex
For some reason, yahoo removed part of my original preg_match_all (the first one) and replaced it with [...]

It looks like this:
_all("/(\([^)]*)\)(.*)(\))/i", $insert, $values,
 
Back
Top