Turbo Tax software - Personal Loans - Remortgages - Mobile Phones - Facebook proxy list

PDA

View Full Version : Yes, another regular expression question


imvain2
Apr 27th 2008, 9:01 pm
I have the below code that "kind of" works.


$content = "Zs dasd jasjd asjdo asjio [mytag 0970897890,222,11] das jio das idopas s sjiopd sd [mytag 123456,356,66]";
preg_match_all("/\[mytag (.+?)\]/ise", $content,$matches);
$X=0;
foreach($matches as $var){
echo $var[$X] . "<br>";
$X+=1;
}


the output is:
[mytag 0970897890,222,11]
123456,356,66

when I just want:
0970897890,222,11
123456,356,66

---------------------------
i know I can use str_replace in my loop to clean the output, however I would like to fix the actual problem with the regular expression.

powerspike
Apr 27th 2008, 9:11 pm
Try the following code,



$content = "Zs dasd jasjd asjdo asjio [mytag 0970897890,222,11] das jio das idopas s sjiopd sd [mytag 123456,356,66]";
preg_match_all("/(0-9\,)/ise", $content,$matches);
$X=0;
foreach($matches as $var){
echo $var[$X] . "<br>";
$X+=1;
}

Hopefully that will give you your desired results.