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

Jonny
  • 2,223
  • 23
  • 30
usman
  • 15
  • 4

1 Answers1

1

Use a DOM Crawler, like this one: http://symfony.com/doc/current/components/dom_crawler.html.

Then you can get the registrant name like this:

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler($htmlFromCurl);

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

Filtering is even easier if you have the CssSelector component installed. This allows you to use jQuery-like selectors to traverse.

You can install the Dom Crawler without using the whole framework

composer require symfony/dom-crawler
Jonny
  • 2,223
  • 23
  • 30
  • but i m unable to do it is there any other way rather than using a composer i m at work and here i found no composer to work with – usman Aug 08 '16 at 09:39
  • You can download it from here, but you will have to require the correct PHP files yourself: https://github.com/symfony/dom-crawler/releases – Jonny Aug 08 '16 at 10:01
  • brother can u guide me i m working on core php knew codeigniter and laravel(a bit) now i wanted my core php to work better can i use active record or anything closer to that so i can reduce my working time by just including composers and saves my time in crud auth or queries – usman Aug 08 '16 at 12:35
  • I have no idea what you're talking about. Both frameworks use composer. – Jonny Aug 08 '16 at 14:59