diff --git a/.gitignore b/.gitignore index fc97d41..7a5bb6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ vendor/* composer.lock composer.phar diff --git a/source/robotstxtparser.php b/source/robotstxtparser.php index 392d750..494ba6b 100644 --- a/source/robotstxtparser.php +++ b/source/robotstxtparser.php @@ -79,14 +79,18 @@ class RobotsTxtParser // robots.txt file content private $content = ''; - + /** + * @var array + */ + private $regExpPatternReplace; + /** * Constructor * * @param string $content - file content * @param string $encoding - encoding */ - public function __construct($content, $encoding = self::DEFAULT_ENCODING) + public function __construct($content, $encoding = self::DEFAULT_ENCODING, array $regExpPatternReplace = array()) { // convert encoding $encoding = !empty($encoding) ? $encoding : mb_detect_encoding($content); @@ -104,6 +108,10 @@ public function __construct($content, $encoding = self::DEFAULT_ENCODING) // parse rules - default state $this->prepareRules(); + + $this->regExpPatternReplace = empty($regExpPatternReplace) + ? array('@' => '\@') + : $regExpPatternReplace; } /** @@ -771,7 +779,7 @@ private function checkBasicRule($rule, $path) { $rule = $this->prepareRegexRule($this->encode_url($rule)); // change @ to \@ - $escaped = strtr($rule, array('@' => '\@')); + $escaped = strtr($rule, $this->regExpPatternReplace); // match result if (preg_match('@' . $escaped . '@', $path)) { $this->log[] = 'Rule match: Path';