如何解决SimpleXMLElement错误?

时间:2011-07-25 00:57:35

标签: php zend-framework centos pear apc

我有一个非常奇怪的错误,无法修复它。试图安装APC,PEAR但继续相同的错误。如何解决这个问题?

[error] [client 127.0.0.1] PHP Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Comment not terminated in /var/www/html/my/application/search/models/Search/Adapter/Web/YahooBoss.php on line 39

<?php

class Search_Adapter_Web_YahooBoss extends Search_Adapter_Abstract implements Search_Adapter_Localized_Interface {

    private $_applicationId;
    private $_locale;
    private $_defaultLocale = 'en_US';

    function __construct($applicationId) {
        $this->_applicationId = $applicationId;
    }

    /**
     * @param $searchString string
     * @param $offset integer
     * @param $count integer
     * @return Search_ResultList
     */
    public function search($searchString, $offset, $count) {
        $rest = new Zend_Rest_Client ( 'http://boss.yahooapis.com' );

            ///Zend_Debug::dump($rest);exit;

        //Set the locale for internal use
        $locale = $this->getWorkingLocale();
        $options = array ('region' => $locale->getRegion (), 'lang' => $locale->getLanguage (), 'start' => $offset, 'count' => $count,'type'=>'html', 'format' => 'xml', 'appid' => $this->_applicationId );

        // < and > characters cause errors
        $searchString = str_replace(array('<','>'),'',$searchString);

        $restUrl = '/ysearch/web/v1/' . rawurlencode ( $searchString );
        $response = $rest->restGet ($restUrl , $options);

        if ($response->isError ()) {
            require_once 'Zend/Service/Exception.php';
            throw new Zend_Service_Exception ( 'An error occurred sending request. Status code: ' . $response->getStatus () );
        }

        $body = $response->getBody ();
        //libxml_use_internal_errors(true);
        $sxe = new SimpleXMLElement ( $body );




# php -r 'phpinfo();' |grep apc
Additional .ini files parsed => /etc/php.d/apc.ini,
apc
MMAP File Mask => /tmp/apc.XXXXXX
apc.cache_by_default => On => On
apc.canonicalize => Off => Off
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => /tmp/apc.XXXXXX => /tmp/apc.XXXXXX
apc.num_files_hint => 1024 => 1024
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 64M => 64M
apc.slam_defense => On => On
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 7200 => 7200
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 7200 => 7200
apc.write_lock => On => On

1 个答案:

答案 0 :(得分:0)

我认为您的问题是由您尝试加载的XML流引起的:它似乎不是有效的xml。

如果是网页,请尝试获取源代码并使用w3c验证程序对其进行验证。在使用simplexml的ordre中,它必须与xhtml严格格式兼容。

如果它是XML流(例如来自api),请检查它是否格式正确(您可以使用任何支持XML的主要IDE