Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: Появились крякозябры

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Описание: После длительной нормальной работы скрипта появились крякозябры
Sanek_OS9
Отправлено: 12 Октября, 2015 - 11:37:54
Post Id



Гость


Покинул форум
Сообщений всего: 115
Дата рег-ции: Окт. 2012  
Откуда: Украина


Помог: 0 раз(а)




Здравствуйте, у меня после длительной нормальной работы скрипта появились крякозябры вместо нормального скрипта. Изменений никаких не делал.
Скрипт о котором идет речь граббер, на моем сайте и на сайте донора используется кодировка utf-8, но недельку назад все сломалось и теперь выводит крякозябры.
Кто может подсказать что случилось?
(Добавление)
Пользуюсь вот таким вот классом
PHP:
скопировать код в буфер обмена
  1. /*
  2.  * This file is part of the zero package.
  3.  * Copyright (c) 2012 olamedia <olamedia@gmail.com>
  4.  *
  5.  * This source code is release under the MIT License.
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10.  
  11. /**
  12.  * Simple HTML parser
  13.  *
  14.  * @author olamedia <olamedia@gmail.com>
  15.  */
  16. class nokogiri implements IteratorAggregate{
  17.         const
  18.         regexp =
  19.         "/(?P<tag>[a-z0-9]+)?(\[(?P<attr>\S+)=(?P<value>[^\]]+)\])?(#(?P<id>[^\s:>#\.]+))?(\.(?P<class>[^\s:>#\.]+))?(:(?P<pseudo>(first|last|nth)-child)(\((?P<expr>[^\)]+)\))?)?\s*(?P<rel>>)?/isS"
  20.         ;
  21.         protected $_source = '';
  22.         /**
  23.          * @var DOMDocument
  24.          */
  25.         protected $_dom = null;
  26.         /**
  27.          * @var DOMDocument
  28.          */
  29.         protected $_tempDom = null;
  30.         /**
  31.          * @var DOMXpath
  32.          * */
  33.         protected $_xpath = null;
  34.         /**
  35.          * @var libxmlErrors
  36.          */
  37.         protected $_libxmlErrors = null;
  38.         protected static $_compiledXpath = array();
  39.         public function __construct($htmlString = ''){
  40.                 $this->loadHtml($htmlString);
  41.         }
  42.         public function getRegexp(){
  43.                 $tag = "(?P<tag>[a-z0-9]+)?";
  44.                 $attr = "(\[(?P<attr>\S+)=(?P<value>[^\]]+)\])?";
  45.                 $id = "(#(?P<id>[^\s:>#\.]+))?";
  46.                 $class = "(\.(?P<class>[^\s:>#\.]+))?";
  47.                 $child = "(first|last|nth)-child";
  48.                 $expr = "(\((?P<expr>[^\)]+)\))";
  49.                 $pseudo = "(:(?P<pseudo>".$child.")".$expr."?)?";
  50.                 $rel = "\s*(?P<rel>>)?";
  51.                 $regexp = "/".$tag.$attr.$id.$class.$pseudo.$rel."/isS";
  52.                 return $regexp;
  53.         }
  54.         public static function fromHtml($htmlString){
  55.                 $me = new self();
  56.                 $me->loadHtml($htmlString);
  57.                 return $me;
  58.         }
  59.         public static function fromHtmlNoCharset($htmlString){
  60.                 $me = new self();
  61.                 $me->loadHtmlNoCharset($htmlString);
  62.                 return $me;
  63.         }
  64.         public static function fromDom($dom){
  65.                 $me = new self();
  66.                 $me->loadDom($dom);
  67.                 return $me;
  68.         }
  69.         public function loadDom($dom){
  70.                 $this->_dom = $dom;
  71.         }
  72.         public function loadHtmlNoCharset($htmlString = ''){
  73.                 $dom = new DOMDocument('1.0', 'UTF-8');
  74.                 $dom->preserveWhiteSpace = false;
  75.                 if (strlen($htmlString)){
  76.                         libxml_use_internal_errors(true);
  77.                         $this->_libxmlErrors = null;
  78.                         $dom->loadHTML('<?xml encoding="UTF-8">'.$htmlString);
  79.                         // dirty fix
  80.                         foreach ($dom->childNodes as $item){
  81.                             if ($item->nodeType == XML_PI_NODE){
  82.                                 $dom->removeChild($item); // remove hack
  83.                                 break;
  84.                             }
  85.                         }
  86.                         $dom->encoding = 'UTF-8'; // insert proper
  87.                         $this->_libxmlErrors = libxml_get_errors();
  88.                         libxml_clear_errors();
  89.                 }
  90.                 $this->loadDom($dom);
  91.         }
  92.         public function loadHtml($htmlString = ''){
  93.                 $dom = new DOMDocument('1.0', 'UTF-8');
  94.                 $dom->preserveWhiteSpace = false;
  95.                 if (strlen($htmlString)){
  96.                         libxml_use_internal_errors(true);
  97.                         $this->_libxmlErrors = null;
  98.                         $dom->loadHTML($htmlString);
  99.                         $this->_libxmlErrors = libxml_get_errors();
  100.                         libxml_clear_errors();
  101.                 }
  102.                 $this->loadDom($dom);
  103.         }
  104.         public function getErrors(){
  105.                 return $this->_libxmlErrors;
  106.         }
  107.         function __invoke($expression){
  108.                 return $this->get($expression);
  109.         }
  110.         public function get($expression, $compile = true){
  111.                 /*if (strpos($expression, ' ') !== false){
  112.                         $a = explode(' ', $expression);
  113.                         foreach ($a as $k=>$sub){
  114.                                 $a[$k] = $this->getXpathSubquery($sub);
  115.                         }
  116.                         return $this->getElements(implode('', $a));
  117.                 }*/
  118.                 return $this->getElements($this->getXpathSubquery($expression, false, $compile));
  119.         }
  120.         protected function getNodes(){
  121.  
  122.         }
  123.         public function getDom($asIs = false){
  124.                 if ($asIs){
  125.                         return $this->_dom;
  126.                 }
  127.                 if ($this->_dom instanceof DOMDocument){
  128.                         return $this->_dom;
  129.                 }elseif ($this->_dom instanceof DOMNodeList || $this->_dom instanceof DOMElement){
  130.                         if ($this->_tempDom === null){
  131.                                 $this->_tempDom = new DOMDocument('1.0', 'UTF-8');
  132.                                 $root = $this->_tempDom->createElement('root');
  133.                                 $this->_tempDom->appendChild($root);
  134.                                 if($this->_dom instanceof DOMNodeList){
  135.                                         foreach ($this->_dom as $domElement){
  136.                                                 $domNode = $this->_tempDom->importNode($domElement, true);
  137.                                                 $root->appendChild($domNode);
  138.                                         }
  139.                                 }else{
  140.                                         $domNode = $this->_tempDom->importNode($this->_dom, true);
  141.                                         $root->appendChild($domNode);
  142.                                 }
  143.                         }
  144.                         return $this->_tempDom;
  145.                 }
  146.         }
  147.         protected function getXpath(){
  148.                 if ($this->_xpath === null){
  149.                         $this->_xpath = new DOMXpath($this->getDom());
  150.                 }
  151.                 return $this->_xpath;
  152.         }
  153.         public function getXpathSubquery($expression, $rel = false, $compile = true){
  154.                 if ($compile){
  155.                         $key = $expression.($rel?'>':'*');
  156.                         if (isset(self::$_compiledXpath[$key])){
  157.                                 return self::$_compiledXpath[$key];
  158.                         }
  159.                 }
  160.                 $query = '';
  161.                 if (preg_match(self::regexp, $expression, $subs)){
  162.                         $brackets = array();
  163.                         if (isset($subs['id']) && '' !== $subs['id']){
  164.                                 $brackets[] = "@id='".$subs['id']."'";
  165.                         }
  166.                         if (isset($subs['attr']) && '' !== $subs['attr']){
  167.                                 $attrValue = isset($subs['value']) && !empty($subs['value'])?$subs['value']:'';
  168.                                 $brackets[] = "@".$subs['attr']."='".$attrValue."'";
  169.                         }
  170.                         if (isset($subs['class']) && '' !== $subs['class']){
  171.                                 $brackets[] = 'contains(concat(" ", normalize-space(@class), " "), " '.$subs['class'].' ")';
  172.                         }
  173.                         if (isset($subs['pseudo']) && '' !== $subs['pseudo']){
  174.                                 if ('first-child' === $subs['pseudo']){
  175.                                         $brackets[] = '1';
  176.                                 }elseif ('last-child' === $subs['pseudo']){
  177.                                         $brackets[] = 'last()';
  178.                                 }elseif ('nth-child' === $subs['pseudo']){
  179.                                         if (isset($subs['expr']) && '' !== $subs['expr']){
  180.                                                 $e = $subs['expr'];
  181.                                                 if('odd' === $e){
  182.                                                         $brackets[] = '(position() -1) mod 2 = 0 and position() >= 1';
  183.                                                 }elseif('even' === $e){
  184.                                                         $brackets[] = 'position() mod 2 = 0 and position() >= 0';
  185.                                                 }elseif(preg_match("/^[0-9]+$/", $e)){
  186.                                                         $brackets[] = 'position() = '.$e;
  187.                                                 }elseif(preg_match("/^((?P<mul>[0-9]+)n\+)(?P<pos>[0-9]+)$/is", $e, $esubs)){
  188.                                                         if (isset($esubs['mul'])){
  189.                                                                 $brackets[] = '(position() -'.$esubs['pos'].') mod '.$esubs['mul'].' = 0 and position() >= '.$esubs['pos'].'';
  190.                                                         }else{
  191.                                                                 $brackets[] = ''.$e.'';
  192.                                                         }
  193.                                                 }
  194.                                         }
  195.                                 }
  196.                         }
  197.                         $query = ($rel?'/':'//').
  198.                                 ((isset($subs['tag']) && '' !== $subs['tag'])?$subs['tag']:'*').
  199.                                 (($c = count($brackets))?
  200.                                         ($c>1?'[('.implode(') and (', $brackets).')]':'['.implode(' and ', $brackets).']')
  201.                                 :'')
  202.                                 ;
  203.                         $left = trim(substr($expression, strlen($subs[0])));
  204.                         if ('' !== $left){
  205.                                 $query .= $this->getXpathSubquery($left, isset($subs['rel'])?'>'===$subs['rel']:false, $compile);
  206.                         }
  207.                 }
  208.                 if ($compile){
  209.                         self::$_compiledXpath[$key] = $query;
  210.                 }
  211.                 return $query;
  212.         }
  213.         protected function getElements($xpathQuery){
  214.                 if (strlen($xpathQuery)){
  215.                         $nodeList = $this->getXpath()->query($xpathQuery);
  216.                         if ($nodeList === false){
  217.                                 throw new Exception('Malformed xpath');
  218.                         }
  219.                         return self::fromDom($nodeList);
  220.                 }
  221.         }
  222.         public function toDom($asIs = false){
  223.                 return $this->getDom($asIs);
  224.         }
  225.         public function toXml(){
  226.                 return $this->getDom()->saveXML();
  227.         }
  228.         public function toArray($xnode = null){
  229.                 $array = array();
  230.                 if ($xnode === null){
  231.                         if ($this->_dom instanceof DOMNodeList){
  232.                                 foreach ($this->_dom as $node){
  233.                                         $array[] = $this->toArray($node);
  234.                                 }
  235.                                 return $array;
  236.                         }
  237.                         $node = $this->getDom();
  238.                 }else{
  239.                         $node = $xnode;
  240.                 }
  241.                 if (in_array($node->nodeType, array(XML_TEXT_NODE,XML_COMMENT_NODE))){
  242.                         return $node->nodeValue;
  243.                 }
  244.                 if ($node->hasAttributes()){
  245.                         foreach ($node->attributes as $attr){
  246.                                 $array[$attr->nodeName] = $attr->nodeValue;
  247.                         }
  248.                 }
  249.                 if ($node->hasChildNodes()){
  250.                         foreach ($node->childNodes as $childNode){
  251.                                 $array[$childNode->nodeName][] = $this->toArray($childNode);
  252.                         }
  253.                 }
  254.                 if ($xnode === null){
  255.                         $a = reset($array);
  256.                         return reset($a); // first child
  257.                 }
  258.                 return $array;
  259.         }
  260.         public function getIterator(){
  261.                 $a = $this->toArray();
  262.                 return new ArrayIterator($a);
  263.         }
  264.         protected function _toTextArray($node = null, $skipChildren = false, $singleLevel = true){
  265.                 $array = array();
  266.                 if ($node === null){
  267.                         if ($this->_dom instanceof DOMNodeList){
  268.                                 foreach ($this->_dom as $node){
  269.                                         if ($singleLevel){
  270.                                                 $array = array_merge($array, $this->_toTextArray($node, $skipChildren, $singleLevel));
  271.                                         }else{
  272.                                                 $array[] = $this->_toTextArray($node, $skipChildren, $singleLevel);
  273.                                         }
  274.                                 }
  275.                                 return $array;
  276.                         }
  277.                         $node = $this->getDom();
  278.                 }
  279.                 if (XML_TEXT_NODE === $node->nodeType){
  280.                         return array($node->nodeValue);
  281.                 }
  282.                 if (!$skipChildren){
  283.                         if ($node->hasChildNodes()){
  284.                                 foreach ($node->childNodes as $childNode){
  285.                                         if ($singleLevel){
  286.                                                 $array = array_merge($array, $this->_toTextArray($childNode, $skipChildren, $singleLevel));
  287.                                         }else{
  288.                                                 $array[] = $this->_toTextArray($childNode, $skipChildren, $singleLevel);
  289.                                         }
  290.                                 }
  291.                         }
  292.                 }
  293.                 return $array;
  294.         }
  295.         public function toTextArray($skipChildren = false, $singleLevel = true){
  296.                 return $this->_toTextArray($this->_dom, $skipChildren, $singleLevel);
  297.         }
  298.         public function toText($glue = ' ', $skipChildren = false){
  299.                 return implode($glue, $this->toTextArray($skipChildren, true));
  300.         }
  301. }
 
 Top
Sanek_OS9
Отправлено: 13 Октября, 2015 - 21:43:42
Post Id



Гость


Покинул форум
Сообщений всего: 115
Дата рег-ции: Окт. 2012  
Откуда: Украина


Помог: 0 раз(а)




Огорчение никто не в курсе? это очень важно Хм
 
 Top
higub
Отправлено: 04 Декабря, 2015 - 22:30:48
Post Id



Новичок


Покинул форум
Сообщений всего: 56
Дата рег-ции: Нояб. 2015  


Помог: 0 раз(а)

[+]


Скорее всего у вас кодировка файла не utf8 Хм
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Кодировки и все смежное »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB