Anidazen Posted July 13, 2006 Share Posted July 13, 2006 Hello.I am running a regular expression with preg_match_all(). All expressions match, but for some reason $matches[1][0] is empty. (The first match.) When tested in a reg_ex editor for group1 matches, the first number DOES appear. I think the expression is valid but somehow PHP isn't retrieving that info!Here is the expression I'm using: preg_match_all('/Gold ([0-9]?\,?[0-9]*).*?\$([0-9]*\.[0-9]*)/s', $content, $matches);Here is the code on which I'm using it: [quote] <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl1:Button1" value="Add to Cart" id="CurList_CurTable__ctl1_Button1" class="add" /> Gold 250 <br /> <span class="sale"> $20.78 </span> <br /> </td> </tr> <tr> <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl2:Button1" value="Add to Cart" id="CurList_CurTable__ctl2_Button1" class="add" /> Gold 500 <br /> <span class="sale"> $39.57 </span> <br /> </td> </tr> <tr> <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl3:Button1" value="Add to Cart" id="CurList_CurTable__ctl3_Button1" class="add" /> Gold 1,000 <br /> <span class="sale"> $77.15 </span> <br /> </td> </tr> <tr> <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl4:Button1" value="Add to Cart" id="CurList_CurTable__ctl4_Button1" class="add" /> Gold 1,500 <br /> <span class="sale"> $112.23 </span> <br /> </td> </tr> <tr> <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl5:Button1" value="Add to Cart" id="CurList_CurTable__ctl5_Button1" class="add" /> Gold 2,000 <br /> <span class="sale"> $146.31 </span> <br /> </td> </tr> <tr> <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl6:Button1" value="Add to Cart" id="CurList_CurTable__ctl6_Button1" class="add" /> Gold 3,000 <br /> <span class="sale"> $216.47 </span> <br /> </td> </tr> <tr> <td class="column1"> <input type="submit" name="CurList:CurTable:_ctl7:Button1" value="Add to Cart" id="CurList_CurTable__ctl7_Button1" class="add" /> Gold 4,000 <br /> <span class="sale"> $282.63 </span> <br /> </td> </tr> </table>[/quote]For some reason, the output I get is 100% correct, but always misses the first 250! $matches[1][0] is empty but $matches[2][0] is correct with the corresponding figure!Here's the code to output (I've checked outside of this code -- $matches[1][0] is somehow empty. So It's not this that's at fault).$i = 0;$matchlength = sizeof($matches[0]);while($i < $matchlength){echo $matches[1][$i] . " gold: $" . $matches[2][$i] . "<br>";$i++;}Here is the output I am getting:gold: $20.78500 gold: $39.571,000 gold: $77.151,500 gold: $112.232,000 gold: $146.313,000 gold: $216.474,000 gold: $282.63 Link to comment https://forums.phpfreaks.com/topic/14491-preg_match-not-listing-first-match-assistance-needed/ Share on other sites More sharing options...
effigy Posted July 13, 2006 Share Posted July 13, 2006 This matches 250 for me. What's your PHP version? Link to comment https://forums.phpfreaks.com/topic/14491-preg_match-not-listing-first-match-assistance-needed/#findComment-57378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.