regex - PHP : complex Regular expression -
hi have created example page .please see here
i want event name , timing seperately. can me?
for example. line
***english* mlb: philadelphia phillies @ miami marlins 12.00am-3.00am stream 7**
note: **english varies time...time varies am,pm
i want event name,timing,and stream number below seperately
mlb: minnesota twins @ atlanta braves 12.00am-3.00am 7
i've tried
$game = file_get_contents("http://livestreamly.com/"); preg_match_all('/<font color="gold">(.*?)<p>/',$game,$match);
this gives whole live. please me.
i've checked site , regex valid problem
/<\/font>([a-za-z0-9\'.: -]+)([0-9]{1,2}.+?[0-9]{1,2}[a,p,a,p,m,m]{2})-([0-9]{1,2}[.:]+?[0-9]{1,2}[a,p,a,p,m,m]{2}) <font color="red">stream ([0-9]+)<\/font>/
i've checked http://regexpal.com/ when use preg_match_all; output array matches contain information need. need escape chars in regex put php variable.
php valid code:
$match = array(); preg_match_all('/<\/font>([a-za-z0-9\'.: -]+)([0-9]{1,2}.+?[0-9]{1,2}[a,p,a,p,m,m]{2})-([0-9]{1,2}[.:]+?[0-9]{1,2}[a,p,a,p,m,m]{2}) <font color="red">stream ([0-9]+)<\/font>/',file_get_contents("http://livestreamly.com/"),$match); print_r($match);
some of output:
[1] => array(37) { [0] => string(45) " mlb: philadelphia phillies @ miami marlins " [1] => string(40) " mlb: minnesota twins @ atlanta braves " [2] => string(39) " mlb: cincinnati reds @ new york mets " [2] => array(37) { [0] => string(14) "12.00am-3.00am" [1] => string(14) "12.00am-3.00am" [2] => string(14) "12.00am-3.00am" [3] => string(14) "12:00am-3:00am" [4] => string(14) "12.15am-2.15am" [5] => string(14) "12.30am-3.30am" [3] => array(37) { [0] => string(1) "6" [1] => string(1) "7" [2] => string(1) "8" [3] => string(1) "9" [4] => string(2) "10"
how works
firstly looks subpattern [a-za-z0-9'.: -]+
means characters a-z , a-z, digits 0-9 ' . : or - must occur @ least once or more. matches name.
([0-9]{1,2}.+?[0-9]{1,2})
later looks first part of hour numerical , has 1 or 2 digits, can character @ least once greedy operator. other number(minutes) @ least 1 or 2 digits.
[a,p,a,p,m,m]{2}
is responsible or or pm or pm can aa or mm doesn't matter here.
<font color="red">stream ([0-9]+)<\/font>
this line responsible getting humber of stream numerical , need @ least 1 digit or more.
Comments
Post a Comment