简体   繁体   中英

Warning: simplexml_load_file()

I have this code

<?php

$url = "_configurations/right_sidebar_links.xml";
$xml = simplexml_load_file($url);

foreach($xml->links as $links)
{
    echo "<li>";
    echo "<a href='".$links->url."'>";
    echo $links->name."</a></li>";
}

?>

that loads xml links from another file, it works fine with links that doesn't have any strange characters but when you enter long link with weird characters it gives an error that is saying

Warning: simplexml_load_file() [function.simplexml-load-file]: _configurations/right_sidebar_links.xml:17: parser error : EntityRef: expecting ';' in .../includes/loadLinks.php on line 8

any help would be much appreciated.

here is an example of the link

http://www.exampe.com/gp/product/B007RT6OZW/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=B007RT6OZW&linkCode=as2&tag=backpaininfor-20

Thanks!

The contents of your XML file are invalid. Make sure it's properly encoded (ie & is &amp; ) and/or CDATA tags are used where necessary.

If you open the XML file in a modern browser, they'll usually give you a detailed answer as to where the error is (line and character).

Also, see this hack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM