Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 ...

share|improve this question
    
Do you get any errors? Or is the PHP code simply not being processed? –  w3d Aug 6 at 22:05

1 Answer 1

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
share|improve this answer
    
When I do that i receive 500 Internal Server Error. –  user3626223 Aug 6 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"?>'; ?>. –  w3d Aug 6 at 22:21
    
Yeee man that is it... Thanks a lot... –  user3626223 Aug 7 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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