PHP爆炸和Get_Url:未显示URL [英] PHP Explode and Get_Url: Not Showing up the URL

查看:57
本文介绍了PHP爆炸和Get_Url:未显示URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点难以理解.

在header.php中,我有以下代码:

in the header.php i have this code:

<?
$ID = $link;
$url = downloadLink($ID);
?>

我通过此变量$ link获得ID-> 12345678 并通过$ url获得来自functions.php的完整链接

I get the ID with this Variable $link --> 12345678 and with $url i get the full link from the functions.php

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

推荐答案

它是用一种奇怪的方式编写的,但基本上downloadLink()的作用是这样的:

It's written in kind of a strange way, but basically what downloadLink() does is this:

  1. http://www.example.com/<ID>/go.html
  2. 下载HTML
  3. 获取HTML,并在出现字符串<iframe的每个点处将其拆分.
  4. 现在,获取HTML中 first <iframe之后的所有内容,并在出现字符串src="的每个点处将其拆分.
  5. 现在将第一个src="之后的所有内容拿走,并在出现"的每个点处将其拆分.
  6. 返回第一个"之前的之前的内容.
  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 ".

因此,这是一种很差的方法,但是有效地它会在HTML代码中寻找这种情况的首次出现:

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

并返回<something>.

一种不同的方法,根据注释的要求:

确实没有任何特定的正确"方法可以执行此操作,但是一种相当简单的方法是将其更改为:

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];
}

这篇关于PHP爆炸和Get_Url:未显示URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆