dqe9657 2012-07-06 11:32
浏览 84

PHP通过xml读取带有特殊字符的链接

I have an xml file that is editable via a webpage where users enter links. This looks like

 <links>
    <link1 path="http://abc.def.com/abcd?id=2&ed=4" > </link1>
 <links>

I read this xml via php and then add a button which will link here. What I'm currently doing is use a str_replace('&', '&amp;',) on the xml string and then a str_replace('&amp;', '&',) on the extracted path. Is there a more elegant way to do this?

  • 写回答

1条回答 默认 最新

  • douji0108 2012-07-06 13:11
    关注

    What you have shown is not an XML file. An XML file cannot contain an unescaped ampersand.

    The URL as stored in the XML should encode ampersand as &amp;. When you read the XML file the XML parser will present you with the unescaped text, that is &. Of course, if you try to read the XML file without doing proper XML parsing, you will be in a mess, as you deserve to be.

    评论

报告相同问题?