ravi181229 Posted November 4, 2008 Share Posted November 4, 2008 Hi, I like to have a php script which reads html page and get me the information. The link for the html page is http://www.nowlive.com/schedule.aspx I want to fetch the following information from the link above(see the view source): Time which is in <span id="ctl00_MainContent_RepeaterSchedule_ctl01_lblDate">Tue, 5:00 PM PST</span> and parameter from ddrivetip() function for all the event/show. The info is in <tr></tr> block for all the event/show: <tr> <td style="width:3px;"></td> <td height="20" align="left" style="width: 125px; color:#eeeeee; font-size:10px;"> <span id="ctl00_MainContent_RepeaterSchedule_ctl06_lblDate">Tue, 5:00 PM PST</span> </td> <td align="left" style="width: 400px;"> <div id="ctl00_MainContent_RepeaterSchedule_ctl06_pnlLiveTitle"> <a style="color:White; font-size:10px;" href="/QuietontheSet" onmouseout="hideddrivetip()" onmouseover="ddrivetip('<table cellpadding=3 border=0 width=300 height=120><tr><td valign=top width=80><img src=http://media2.nowlive.com/member_image.asp?file=/images/members/100288149/100288149_av.jpg width=100 height=100 class=thumb /></td><td valign=top width=*> <a href=#><strong>White Soaring Eagle Inter</strong></a><br /><img id=rating src=/images/flag-M.gif vspace=4 /><br />White Soaring Eagle, formerly known as Two Feathers is a musician with a flare for eclectic sounds. Being a descendant of the Seihlagee Nation (Cherokee), he’s always enjoyed music of most kinds from</td></tr></table>')"> White Soaring Eagle Inter </a> </div> </td> </tr> Please help me. Thanks, Ravi Link to comment https://forums.phpfreaks.com/topic/131338-solved-read-html-page/ Share on other sites More sharing options...
thebadbad Posted November 4, 2008 Share Posted November 4, 2008 Easy - if you know how to do it : <?php $source = file_get_contents('http://www.nowlive.com/schedule.aspx'); preg_match_all('~id="ctl\d+_MainContent_RepeaterSchedule_ctl\d+_lblDate">([^<]*).+?ddrivetip\(\'([^\']*)~is', $source, $matches); //remove full pattern matches from $matches array_shift($matches); //have a look at $matches echo '<pre>', print_r($matches, true), '</pre>'; ?> Important parts of the regular expression (first parameter in preg_match_all()): \d+ matches 1 or more digits. ([^<]*) matches any character NOT a < 0 or more times, and saves match in $matches. .+? matches any character 1 or more times. Ungreedy, so it stops matching when the following string (ddrivetip..) is found. ([^\']*) matches any character NOT a ' 0 or more times, and saves the match in $matches. is are pattern modifiers, making the search case insensitive and dots match new lines also. Just ask if you need help rearranging the data in $matches. Link to comment https://forums.phpfreaks.com/topic/131338-solved-read-html-page/#findComment-682030 Share on other sites More sharing options...
ravi181229 Posted November 4, 2008 Author Share Posted November 4, 2008 Hi, Thanks a lot. I would also like to get all the href(first one since there are two) info (href="/QuietontheSet") for those shows/events. So, how do I arrange it in this preg_match_all() ? Thanks, Ravi Link to comment https://forums.phpfreaks.com/topic/131338-solved-read-html-page/#findComment-682062 Share on other sites More sharing options...
thebadbad Posted November 4, 2008 Share Posted November 4, 2008 No problem. And I hope you're learning a bit too. Use this regex instead: preg_match_all('~id="ctl\d+_MainContent_RepeaterSchedule_ctl\d+_lblDate">([^<]*).+?href="([^"]*).+?ddrivetip\(\'([^\']*)~is', $source, $matches); Link to comment https://forums.phpfreaks.com/topic/131338-solved-read-html-page/#findComment-682084 Share on other sites More sharing options...
ravi181229 Posted November 4, 2008 Author Share Posted November 4, 2008 Hi, This has been really a great and good lesson for me. I really would like to learn regex and learned lot from your post. Thanks a lot. Ravi Link to comment https://forums.phpfreaks.com/topic/131338-solved-read-html-page/#findComment-682089 Share on other sites More sharing options...
thebadbad Posted November 4, 2008 Share Posted November 4, 2008 Good to hear Link to comment https://forums.phpfreaks.com/topic/131338-solved-read-html-page/#findComment-682098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.