开发者

T_STRING error even when I don't have any PHP code, just the open close PHP markings [duplicate]

This question already has answers here: PHP error in .xml file? (3 answers) Closed 9 years ago.

Yes, another one of these T_STRING errors...but hopefully this one is different.

Here is all the code I have on my page:

<?php


?>
<?xml version="1.0" encoding="UTF-8" ?> 
<urlset xmlns="http://www.sitemaps.org/schemas/开发者_StackOverflow社区sitemap/0.9"> 


</urlset>

As you can probably see, I'm trying to do a sitemap for my site. But I didn't put anything on it and I already have a

Parse error: syntax error, unexpected T_STRING in ..../sitemap.php on line 4

Which points to the end of PHP code marking ?>

Any input much appreciated. Thanks.


Try

<?php

   echo '<?xml version="1.0" encoding="UTF-8" ?> ';
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 


</urlset>

http://sandbox.phpcode.eu/g/4a51c

problem are these php tags, open-short-tags are probably allowed on your server


There is no reason to include/require XML in PHP.
Proper handling of XML should always use XML handling function/class like

  • SimpleXML
  • DOMDocument
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜