PHP code example of diggin / diggin-robotrules
1. Go to this page and download the library: Download diggin/diggin-robotrules 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/ */
diggin / diggin-robotrules example snippets
php
use Diggin\RobotRules\Accepter\TxtAccepter;
use Diggin\RobotRules\Parser\TxtStringParser;
$robotstxt = <<<'ROBOTS'
# sample robots.txt
User-agent: YourCrawlerName
Disallow:
User-agent: *
Disallow: /aaa/ #comment
ROBOTS;
$accepter = new TxtAccepter;
$accepter->setRules(TxtStringParser::parse($robotstxt));
$accepter->setUserAgent('foo');
var_dump($accepter->isAllow('/aaa/')); //false
var_dump($accepter->isAllow('/b.html')); //true
$accepter->setUserAgent('YourCrawlerName');
var_dump($accepter->isAllow('/aaa/')); // true