Page 1 of 1

very simple regex won't work for me

Posted: Mon Jul 02, 2007 6:15 am
by mzfp2
I'm trying to get the folloinwg reg ex to return a string two parts :

this string would be :

Code: Select all

$string = product_url=name
preg_match_all("#(product_url)=(.*?)#i", $string, $arr_Temp);
Ideally it should return either side of the = in the string as two seperate strings, product_url and name


However the above regex just doesn't seem to return the second part, instead it returns :

Code: Select all

Array
(
    [0] => Array
        (
            [0] => product_url=
        )

    [1] => Array
        (
            [0] => product_url
        )

    [2] => Array
        (
            [0] => 
        )

)

And I just can't figure out why, anyone able to help?

Thanks

Posted: Mon Jul 02, 2007 6:28 am
by volka
Remove the question mark from your expression.

Posted: Mon Jul 02, 2007 6:44 am
by superdezign
volka wrote:Remove the question mark from your expression.
Or give it somewhere to end, such as '$'.

Posted: Mon Jul 02, 2007 6:51 am
by Jenk
If it must have data after the '=' use '+' instead of '*'

Posted: Mon Jul 02, 2007 7:01 am
by stereofrog

Code: Select all

list($url, $name) = explode('=', $string);
;)