Yes, another regular expression question

Discussion in 'PHP' started by imvain2, Apr 27, 2008.

  1. #1
    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;
        }
    
    PHP:
    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.
     
    imvain2, Apr 27, 2008 IP
  2. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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;
        }
    
    Code (markup):
    Hopefully that will give you your desired results.
     
    powerspike, Apr 27, 2008 IP