I want to use PHP inside XML. I create some XML file and everything is OK on my local WAMP server. But online (on ipage server) just problem. I include

AddHandler application/x-httpd-php .xml

in .htaccess file. I saw server can't see something like

<src lang='en'><?php echo "files/en/strana1.jpg"; ?></src>

This is part of XML file. But this cod work perfekt in localhost WAMP server. How to echo/print some text with PHP inside XML??? Maybe problem is in server configuration or ...

  • Do you get any errors? Or is the PHP code simply not being processed? – MrWhite Aug 6 '14 at 22:05

Make sure that short tags are disabled in your production environment as <? is used by PHP and XML and will conflict when you use the two together. WAMP has short tags disabled by default but most web hosts do not to ensure greater compatibility with older PHP scripts.

Since the odds are you won't be able to change the php.ini file of your host you can try to change this in your htaccess file by placing the following line in it:

php_value short_open_tag 0
  • When I do that i receive 500 Internal Server Error. – user3626223 Aug 6 '14 at 21:14
  • AFAIK this is only really a problem with the XML prolog eg. <?xml version="1.0"?>. If your XML files are being processed by PHP and you have short open tags enabled then the XML prolog gets processed as PHP and you end up with a fatal parse error. Other PHP blocks in the XML file would simply get processed as PHP (before the XML is processed). The workaround here is to echo the XML prolog, eg. <?php echo '<?xml version="1.0"?>'; ?>. – MrWhite Aug 6 '14 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.