PHP Explode and Get_Url: Not Showing up the URL

末鹿安然 提交于 2019-12-13 20:28:07

问题


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:

  1. Download the HTML from http://www.example.com/<ID>/go.html
  2. Take the HTML, and split it at every point where the string <iframe occurs.
  3. Now take everything that came after the first <iframe in the HTML, and split it at every point where the string src=" appears.
  4. Now take everything after the first src=" and split it at every point where " appears.
  5. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!