jordan443 Posted April 25, 2013 Share Posted April 25, 2013 So I'm tried to make a script that grabs html from a page and echos a part of it. I wanted to make it start before <h1 class="ttl"> and end before <b>Tagged as</b>. Heres what I have: <?php $file_contents = file_get_contents('http://eyemanga.com/beelzebub/'); $start = strpos($file_contents, '<h1 class="ttl">'); $end = strpos($file_contents, '<b>Tagged as</b>', $start); $code = substr($file_contents, $start, $end); echo $code; ?> When I use it it starts at the right place but it doesn't end in the same place I defined. Any ideas?? Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 25, 2013 Share Posted April 25, 2013 The third parameter to substr is the LENGTH not the POSITION. You need to determine how many bytes you want. Quote Link to comment Share on other sites More sharing options...
Solution Dathremar Posted April 25, 2013 Solution Share Posted April 25, 2013 As the documentation says http://www.php.net/manual/en/function.substr.php string substr ( string $string , int $start [, int $length ] ) You need to put something like: $code = substr($file_contents, $start, ($end - $start)); 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.