-3

I'm using curl to get my values from a site name PKNiC

My code is:

function _isCurl() {
    return function_exists('curl_version');
}

if (_iscurl()) {
    //curl is enabled
    $url = "https://pk6.pknic.net.pk/pk5/lookup.PK?name=cat.com.pk&jsonp=?";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    var_dump($output);
    // Curl operations finished
} else {
    echo "CURL is disabled";
}

Now when I run this program it returns a string to me with whole page print on it as a single string.

enter image description here

I need registrant name, expiry date, create date, contacts. How do I get those things? I have no idea how it works and it just provide me a single string when I use var_dump or print_r or any thing to view it. How to get the record of my choice?

4

1 回答 1

1

使用 DOM Crawler,例如:http ://symfony.com/doc/current/components/dom_crawler.html 。

然后您可以像这样获取注册人名称:

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler($htmlFromCurl);

$crawler = $crawler->filter('.whitebox tr:nth-child(3) td:last-child');

如果安装了 CssSelector 组件,过滤会更容易。这允许您使用类似 jQuery 的选择器进行遍历。

您可以在不使用整个框架的情况下安装 Dom Crawler

composer require symfony/dom-crawler
于 2016-08-08T08:52:41.227 回答