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?? Link to comment https://forums.phpfreaks.com/topic/277318-substr-not-working/ 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. Link to comment https://forums.phpfreaks.com/topic/277318-substr-not-working/#findComment-1426646 Share on other sites More sharing options...
Dathremar Posted April 25, 2013 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)); Link to comment https://forums.phpfreaks.com/topic/277318-substr-not-working/#findComment-1426647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.