PHP code example of gidlov / copycat

1. Go to this page and download the library: Download gidlov/copycat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gidlov / copycat example snippets


$cc = new Copycat;
$cc->setCURL(array(
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_CONNECTTIMEOUT => 5,
  CURLOPT_HTTPHEADER, "Content-Type: text/html; charset=iso-8859-1",
  CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17',
));

$cc->match(array(
    'score' => '/itemprop="ratingValue">(.*?)</ms',))
  ->URLs('http://imdb.com/title/tt0246578/')

$cc->match(array(
    'score' => '/itemprop="ratingValue">(.*?)</ms',))
  ->fillURLs(array(
    'query' => 'http://www.bing.com/search?q=',
    'regex' => '/<a href="(http:\/\/www.imdb.com\/title\/tt.*?\/)".*

$cc->match(array(
    'title' => '/<title>(.*?)\(.*?<\/title>/ms',
    'description' => '/itemprop="description">(.*?)</ms',
    'score' => '/itemprop="ratingValue">(.*?)</ms',
    'votes' => '/itemprop="ratingCount">(.*?)</ms',
    'year' => '/class="nobr">.*

  ->callback(array(
    '_all_' => array('trim'
    ),
  );

$result = $cc->get();

  ->callback(array(
    '_all_' => array('trim'),
    'title' => array(
      function($string) {
        return str_replace(' ', '_', $string);
      },
    ),
    'actors' => array(
      function($string) {
        return $string.', ';
      },
    ),
  ));

'Copycat' => 'Gidlov\Copycat\Copycat',