且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建 URL 字符串时 XML 中的 & 符号问题

更新时间:2022-06-15 19:17:19

如果你在 XML/HTML 中插入一些东西,你应该总是使用 htmlspecialchars 函数.这会将您的字符串转义为正确的 XML 语法.

If you are inserting something into XML/HTML you should always use the htmlspecialchars function. this will escape your strings into correct XML syntax.

但是您遇到了第二个问题.您已将第二个网址添加到第一个网址.这也需要转义为 url 语法.为此,您需要使用 urlencode.

but you are running into a second problem. your have added a second url to the first one. this need also escaped into url syntax. for this you need to use urlencode.

<node><?php echo htmlspecialchars('http://aflite.co.uk/track/?aid=13414&mid=32532&aref=chris&dl='.urlencode('http://www.google.com/')); ?></node>