Can I include PHP in an XML file?

前端 未结 2 1609
余生分开走
余生分开走 2021-01-26 11:50

I am trying to create an automatic \"sitemap.xml\", I already followed the instructions provided by Google to create one, and here is what I currently have:

<         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 12:35

    The answer to your question is: yes, you can embedded PHP in XML. PHP is specifically designed to be embedded: that's why 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.

提交回复
热议问题