Link to home
Create AccountLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

php pattern for preg_match_all

hello there,
I would like to match all of the images that have been downloaded between 120 and 150.. something like this but its not working..

<SPAN class=fcg>[120-150].*?downloaded images</SPAN>

this is the original code..

<SPAN class=fcg>2 downloaded images</SPAN>
<SPAN class=fcg>130 downloaded images</SPAN>
<SPAN class=fcg>25 downloaded images</SPAN>
<SPAN class=fcg>552 downloaded images</SPAN>
<SPAN class=fcg>6592 downloaded images</SPAN>
<SPAN class=fcg>64 downloaded images</SPAN>
Avatar of te-edu
te-edu
Flag of Serbia image

"/12[0-9]|13[0-9]|14[0-9]|15[0-9]/"


<SPAN class=fcg>120 downloaded images</SPAN>
<SPAN class=fcg>130 downloaded images</SPAN>
<SPAN class=fcg>25 downloaded images</SPAN>
<SPAN class=fcg>145 downloaded images</SPAN>
<SPAN class=fcg>6592 downloaded images</SPAN>
<SPAN class=fcg>64 downloaded images</SPAN>

Open in new window

This is better

"/1[2-5][0-9]/"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You are right        

"/1[2-4][0-9]|150/"
sample

<?php
$html = "
<SPAN class=fcg>2 downloaded images</SPAN>
<SPAN class=fcg>130 downloaded images</SPAN>
<SPAN class=fcg>25 downloaded images</SPAN>
<SPAN class=fcg>552 downloaded images</SPAN>
<SPAN class=fcg>152 downloaded images</SPAN>
<SPAN class=fcg>150 downloaded images</SPAN>
<SPAN class=fcg>6592 downloaded images</SPAN>
<SPAN class=fcg>64 downloaded images</SPAN>
<SPAN class=fcg>120 downloaded images</SPAN>
<SPAN class=fcg>100 downloaded images</SPAN>
<SPAN class=fcg>1300 downloaded images</SPAN>
";

preg_match_all("/(<SPAN class=fcg>1([2-4]\d|50) downloaded images<\/SPAN>)/",
    $html,
    $matches, PREG_PATTERN_ORDER);

print_r($matches);
?>