I created a function to pass all url calls through the curl getcurl($url)
, making it easier to read the pages and their contents.
We use a kind of loop that will go through all the sub-links you have on the page, until you get to the final page, when it arrives there, if($link)
is no longer called, and your regex file: "(. +?)"
is executed, capturing the desired content.
The script is written in a simple way.
$url = "http://www.exemplo.com/content.html";
$file_contents = getcurl($url);
preg_match('/<iframe name="Font" ="" src="https://stackoverflow.com/questions/46864238/(.*?)"https://stackoverflow.com/", $file_contents, $match_url);
@$match = $match_url[1];
function get_redirect($link){
$file_contents = getcurl($link);
preg_match('/<a href="https://stackoverflow.com/questions/46864238/(.*?)"https://stackoverflow.com/", $file_contents, $match_url);
@$link = $match_url[1];
if($link){
return get_redirect($link);
}else {
preg_match('/file: "(.+?)"https://stackoverflow.com/",$file_contents, $match_content_url);
@$match_content_url = $match_content_url[1];
return $match_content_url;
}
}
function getcurl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$url = curl_exec($ch);
curl_close ($ch);
return $url;
}
$content = get_redirect($match);
echo $content;
1
solved How to play this python code in php?