Canman2005 Posted April 16, 2009 Share Posted April 16, 2009 Hi all I have the following code if ($source = file_get_contents("http://help.websiteos.com/websiteos/example_of_a_simple_html_page.htm")) { $search = "<h1>Example of a simple HTML page</h1>"; $newText = substr($source,strpos($source, $search)+strlen($search), 100); echo $newText; } else { print "error"; } This grabs the first 100 characters of the HTML code from an external source starting from the defined section of code. Rather than grabbing the first 100 characters, is there a way to define an end tag? So it would grab everything from the start and end tags? Does that make much sense? Thanks very much Dave Quote Link to comment Share on other sites More sharing options...
premiso Posted April 16, 2009 Share Posted April 16, 2009 preg_match Regular Expressions is where you want to go. <?php if ($source = file_get_contents("http://help.websiteos.com/websiteos/example_of_a_simple_html_page.htm")) { $search = "~<h1>(.*)</h1>~s"; preg_match($search, $source, $match); echo $match[1]; } else { echo "error"; } ?> Quote Link to comment Share on other sites More sharing options...
Zane Posted April 16, 2009 Share Posted April 16, 2009 either way, you'll have to read the entire file into buffer unless you use fseek and cut some of it off. Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted April 16, 2009 Author Share Posted April 16, 2009 Thank you very much What would be the best way to grab the following from the external HTML <table id="Table1" cellspacing="1" cellpadding="1" border="1"> <tr> <td height="18" colspan="2"><a id="_ctl5_DesktopThreePanes1_ThreePanes__ctl6_LbShoppingCart" href="javascript:__doPostBack('_ctl5$DesktopThreePanes1$ThreePanes$_ctl6$LbShoppingCart','')" style="font-size:X-Small;font-weight:bold;"> View Cart</a> </td> </tr> <tr> <td height="18"><span id="_ctl5_DesktopThreePanes1_ThreePanes__ctl6_Label3" style="font-size:XX-Small;">Line Items</span></td> <td height="18"><span id="_ctl5_DesktopThreePanes1_ThreePanes__ctl6_LblTotalLineItems" style="font-size:XX-Small;">0</span></td> </tr> <tr> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td><span id="_ctl5_DesktopThreePanes1_ThreePanes__ctl6_Label1" style="font-size:XX-Small;width:56px;">SubTotal</span></td> <td><span id="_ctl5_DesktopThreePanes1_ThreePanes__ctl6_LblSubTotal" style="font-size:XX-Small;">$Zero</span></td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted April 16, 2009 Author Share Posted April 16, 2009 Any ideas anyone? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.