Can I include PHP in an XML file?

情到浓时终转凉″ 提交于 2019-12-02 11:09:16

I, personally have never used include when creating a site map but I wouldn't see it as a problem as long as you are using valid xml elements.

You can create your xml using some of the php classes for it and just defining your content type like: header ("Content-type: text/xml; charset=UTF-8"); and from there you can instantiate your xml classes if you chose or do it all by hand

The answer to your question is: yes, you can embedded PHP in XML. PHP is specifically designed to be embedded: that's why <?php...?> tags exist in the first place. And PHP doesn't know or care where you embed it as long as:

  • The file is sent to the PHP interpreter.
  • There's nothing in the host document that inadvertently looks like a PHP start tag.

Such answer is basically irrelevant given what you want to do. Google sitemaps are XML files with a very specific syntax. Injecting the HTML code of your main menu will not make a sitemap out of it, just like opening a MP3 file in your text editor and typing your name in the middle of it will not make Freddy Mercury sing it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!