问题
I'm trying to require()
my template for rss feed in php. Unfortunately I need to have shorthand tags enabled on server I'm working with.
I have to start my rss with <?xml version="1.0" encoding="UTF-8" ?>
and <? ... ?>
confuses php into thinking he has to parse that line of code.
Is there a way to "escape" that?
here's just the full code of my rss template that I'm trying to include into main php file:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Kokodakalo!</title>
<link>http://127.0.0.1/koko/</link>
<description>Usluga slična twitteru</description>
<?php $data = $controller->getData(); foreach($data as $post):?>
<?php require('views/Rss/item.part.v.htm');?>
<?php endforeach;?>
</channel>
</rss>
</xml>
回答1:
For XML files, the <?xml version="1.0" encoding="UTF-8" ?>
is optional (and actually the default like you write it), so you can just remove it and therefore could fix the problem for this case.
回答2:
You could <?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
来源:https://stackoverflow.com/questions/10457409/escaping-on-php-shorthand-enabled-server-when-using-require