Question

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..

Was it helpful?

Solution

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];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top