parser error : String not started expecting ' or " in php

后端 未结 3 569
孤城傲影
孤城傲影 2021-01-14 05:01

Hi I\'m trying to convert the XML file into associative array by using the following code

$xmlUrl = \'../products.xml\';
$xmlStr = file_get_contents($xmlUrl)         


        
相关标签:
3条回答
  • 2021-01-14 05:29

    Just out of curiosity, why aren't you using simplexml_load_file()?

    0 讨论(0)
  • 2021-01-14 05:32

    This is probably caused by magic_quotes_runtime adding backslashes when you call file_get_contents. Try the following:

    $xmlUrl = '../products.xml';
    $xmlStr = file_get_contents($xmlUrl); 
    if (get_magic_quotes_runtime())
    {
        $xmlStr = stripslashes($xmlStr);
    }
    $xmlObj = simplexml_load_string($xmlStr);  print_r ($xmlObj);exit;
    $arrXml = objectsIntoArray($xmlObj);    $xmlStr = file_get_contents($xmlUrl);
    

    Alternatively you could disable magic_quotes_runtime (although this may have effects elsewhere in your script) in your PHP configuration, via .htaccess, or by adding the following near the top of your script:

    set_magic_quotes_runtime(false);
    
    0 讨论(0)
  • 2021-01-14 05:53

    You should fix your XML string, it's not valid. If you want to keep the XML as is and avoid validation errors, use the 3rd argument of simplexml_load_string() to set the right options, see http://php.net/manual/fr/function.simplexml-load-string.php and http://www.php.net/manual/fr/libxml.constants.php

    Btw I don't understand why it shows your XML with escaped quotes, is it escaped in the source file?

    0 讨论(0)
提交回复
热议问题