Page 1 of 1

PHP reg expr question

Posted: Mon Oct 12, 2009 11:43 pm
by eatsubway
I'm looking to parse some php code...

I have the string "111,222?333,444"

I'm trying to get two variables $var1 = 333 and $var2 = 444

the number characters are not necessarily in groups of three (there maybe one or more numbers). I'm trying to get the numbers to the right of the question mark but before the comma into one variable, and the remaining numbers after the second comma into another variable.

thanks for your help

Re: PHP reg expr question

Posted: Mon Oct 12, 2009 11:48 pm
by requinix

Code: Select all

$string = "111,222?333,444";
 
strtok($string, "?"); // ignore the first part
$before = strtok(","); // the stuff before the first comma
$after = strtok(""); // the rest of the string