PHP reg expr question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eatsubway
Forum Newbie
Posts: 1
Joined: Mon Oct 12, 2009 11:37 pm

PHP reg expr question

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP reg expr question

Post 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
Post Reply