Jump to content

[SOLVED] General Query / Problem


AP-Richard

Recommended Posts

Hello,

 

First of all - I'm quite new to Regex, but knowing the amount of work it could save me when programming, I thought I should learn it.

 

Well.. I came across a problem quite quickly. First of all, lets get to my code.

 

The Code

 

<?php
$xml = "<game id='123'>Testing, 123, 1</game> <game id='456'>Testing, 456, 1</game>";

preg_match_all("/<game id='[0-9]+'>.+<\/game>/", $xml, $matches);

print_r($matches);

 

The Output

 

Array
(
    [0] => Array
        (
            [0] => <game id='123'>Testing, 123, 1</game> <game id='456'>Testing, 456, 1</game>
        )

)

 

 

The Problem

 

Well, as you can see, I expected it, to cut it at </game>, as thats what I put in my regex (/<game id='[0-9]+'>.+<\/game>/), but it just carried on, till it got to the last </game> (I assume?)

 

Can anyone shed some light on this problem? as I'm SURE its something i've done wrong.

 

Thanks,

Richard

 

 

 

 

 

 

 

PS.

 

Expected output would be:

 

Array
[0] => Array
     [0] => <game id='123'>Testing, 123, 1</game>
     [1] => <game id='456'>Testing, 456, 1</game>

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/88489-solved-general-query-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.