问题
its a little bit hard to understand.
in the header.php i have this code:
<?
$ID = $link;
$url = downloadLink($ID);
?>
I get the ID with this Variable $link --> 12345678 and with $url i get the full link from the functions.php
in the functions.php i have this snippet
function downloadlink ($d_id)
{
$res = @get_url ('' . 'http://www.example.com/' . $d_id . '/go.html');
$re = explode ('<iframe', $res);
$re = explode ('src="', $re[1]);
$re = explode ('"', $re[1]);
$url = $re[0];
return $url;
}
and normally it prints the url out.. but, i cant understand the code..
回答1:
It's written in kind of a strange way, but basically what downloadLink()
does is this:
- Download the HTML from
http://www.example.com/<ID>/go.html
- Take the HTML, and split it at every point where the string
<iframe
occurs. - Now take everything that came after the first
<iframe
in the HTML, and split it at every point where the stringsrc="
appears. - Now take everything after the first
src="
and split it at every point where"
appears. - Return whatever was before the first
"
.
So it's a pretty poor way of doing it, but effectively it looks for the first occurence of this in the HTML code:
<iframe src="<something>"
And returns the <something>
.
Edit: a different method, as requested in comment:
There's not really any particular "right" way to do it, but a fairly straightforward way would be to change it to this:
function downloadlink ($d_id)
{
$html = @get_url ('' . 'http://www.example.com/' . $d_id . '/go.html');
preg_match('/\<iframe src="(.+?)"/', $html, $matches);
return $matches[1];
}
来源:https://stackoverflow.com/questions/2563256/php-explode-and-get-url-not-showing-up-the-url