views:

183

answers:

1

hello! 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  A: 

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/&lt;ID&gt;/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];
}
Chad Birch
thank you for the answer, normally it takes the url in the iframe.. how can i get it the right way?
elmaso
how can i print the url? with:<?$ID = $link;$url = downloadLink($ID);?><?php echo $url; ?> ?
elmaso
Yes, that should do it.
Chad Birch
:( nothing happens or should I write <?php echo $matches;?> ?
elmaso