Hi all,
I need to check every hour, a web site that contains time and status information about trains.
I am using preg_match_all and I am grabing successfully the name of each train and the frecuency
time, but I have problems with the status tag. I think that the main problem is that the end tag
is in a new line; preg_match_all does not match </status>, so I get a NULL value in the $status array.
Obviously I cannot modify the source page because it is not mine.
For some reason it has some CRs/LFs in wrong places and the tags are untidy.
exact source Web page:
<report><line><name>Train A</name><status>
</status><frecuency>269</frecuency></line><line><name>Train B</name><status>Train delayed 5 minutes
</status><frecuency></frecuency></line><line><name>Train C</name><status>
</status><frecuency>280</frecuency></line><line><name>Train D</name><status>
</status><frecuency>209</frecuency></line><line><name>TrainE</name><status>Train delayed 9 minutes
</status><frecuency></frecuency></line><line><name>Train P</name><status>
</status><frecuency>420</frecuency></line><line><name>Train U</name><status>
</status><frecuency>1210</frecuency></line>
</report>
If the train is on time, status is blank.
If the train is not on time, frecuency is blank and status has the explanation of the problem.
This is the piece of code I have tried (I am not very good for Regex...) :
<?
preg_match_all("|<name>(.)</name>|",$read_metro,$lines);
preg_match_all("|<status>(.)</status>|",$leer_metro,$status);
preg_match_all("|<frecuency>(.*)</frecuency>|",$read_metro,$frec);
preg_match_all("/<name>(.)<\/name>/is",$read_metro,$lines);
preg_match_all("/<status>(.)<\/status>/is",$leer_metro,$status);
preg_match_all("/<frecuency>(.*)<\/frecuency>/is",$read_metro,$frec);
preg_match_all("/<name>(.)<\/name>/m",$read_metro,$lines);
preg_match_all("/<status>(.)<\/status>/m",$leer_metro,$status);
preg_match_all("/<frecuency>(.*)<\/frecuency>/m",$read_metro,$frec);
preg_match_all("/<name>(.)<\/name>/s",$read_metro,$lines);
preg_match_all("/<status>(.)<\/status>/s",$leer_metro,$status);
preg_match_all("/<frecuency>(.*)<\/frecuency>/s",$read_metro,$frec);
?>
None of these options work properly.
Please I would need help ASAP!
Thank you in advance