使用Curl获取远程页面源如何根据它的数量只回显代码的一行 [英] Using Curl to get remote page source how to echo only one line of the code based on its number

查看:429
本文介绍了使用Curl获取远程页面源如何根据它的数量只回显代码的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在得到远程页面的源代码远程页面的url动态地从用户点击URL根据数组 array('event_id','tv_id',' tid','channel'):我使用下面的代码来获取谁的页面源代码和它的工作原理。

I am working n getting the source code of remote page the url of that remote page it got dynamically from the url the user click according to the arrays array('event_id', 'tv_id', 'tid', 'channel') : i use the code below to get the who;e page source and it works great.

<?php
$keys = array('event_id', 'tv_id', 'tid', 'channel'); // order does matter
$newurl = 'http://lsh.streamhunter.eu/static/popups/';
foreach ($keys as $key)
    $newurl.= empty($_REQUEST[$key])?0:$_REQUEST[$key];

$newurl.='.html';
    function get_data($newurl) 
    { 
       $ch = curl_init();
       $timeout = 5;
       //$userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.X.Y.Z Safari/525.13.";
       $userAgent = "IE 7 – Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)";
      curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
      curl_setopt($ch, CURLOPT_FAILONERROR, true);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_setopt($ch,CURLOPT_URL,$newurl);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;

    }

    $html = get_data($newurl);

    echo $html

?>

这里的诀窍是我只想回显代码的第59行

the trick here is that i want to echo only line no 59 of the code how to do so?

推荐答案

在您的代码中,使用 file_get_contents get_data 函数,因此我从示例中删除了它。

In your code you are using file_get_contents instead of the get_data function so I removed it from the example.

<?php
    $keys = array('event_id', 'tv_id', 'tid', 'channel'); // order does matter
    $newurl = 'http://lsh.streamhunter.eu/static/popups/';
    foreach ($keys as $key)
        $newurl.= empty($_REQUEST[$key])?0:$_REQUEST[$key];

    $newurl.='.html';


    $html = file_get_contents($newurl);
    $html = explode("\n",$html);
    echo $html[58];

?>

这篇关于使用Curl获取远程页面源如何根据它的数量只回显代码的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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