I want to do a simple thing: extract from a string (that is an HTML file) some specific parts of the code.
For example:
//Get a string from a website:
$homepage = file_get_contents('http://mywebsite.org');
//Then, search a particulare substring between two strings:
echo magic_substr($homepage, "<script language", "</script>");
//where magic_substr is this function (find in this awesome website):
function magic_substr($haystack, $start, $end) {
$index_start = strpos($haystack, $start);
$index_start = ($index_start === false) ? 0 : $index_start + strlen($start);
$index_end = strpos($haystack, $end, $index_start);
$length = ($index_end === false) ? strlen($end) : $index_end - $index_start;
return substr($haystack, $index_start, $length);
}
The output I want to get is, in this case, all the scripts on a page. However in my case, I can get only the first script. I think it's right because there aren't any recursions. But I don't know what's the best way to do this! Any suggestions?