예제 #1
0
파일: hicurl.php 프로젝트: clox/hicurl
 /**
  * Takes reference of content-string and utf8-encodes it if necessary and also does the validation which determines
  * if the request was deemed successful or not.
  * @param &string $content Content-string to be parsed and validated. Note that the input-string will be modified.
  * @param array $headers Headers-array belongin to the content.
  * @param array $settings The current state of settings.
  * @param &DOMXPath $domXpath The DOMXPath-object will be set to this out argument if settings->xpath is set.
  * @return bool|string Returns false if no error was encountered, otherwise a string describing the error.*/
 private static function parseAndValidateResult(&$content, $headers, $settings, &$outputArray)
 {
     if (ord($content[0]) == 0x1f && ord($content[1]) == 0x8b) {
         $content = gzdecode($content);
     }
     //utf8 is needed to json-decode correctly
     //can't blindly utf8-encode or data will be corrupted if it already was utf8 encoded.
     if (strpos($headers['content_type'], 'utf-8') === false) {
         $content = utf8_encode($content);
     }
     if ($headers['http_code'] == 404) {
         return 'HTTP code 404';
     }
     if ($settings['retryOnNull'] && $content === null) {
         return 'Null content';
     }
     if ($settings['retryOnIncompleteHTML'] && !preg_match("/<\\/html>\\s*\$/", $content)) {
         return 'Cut off HTML';
     }
     if (!empty($settings['xpath'])) {
         return Hicurl::xPathEvaluate($settings['xpath'], $content, $outputArray);
     }
     return false;
 }