Welcome Guest, Not a member yet? Register   Sign In
Strange echo things happening
#1

[eluser]Boardy[/eluser]
Hi,

I'm trying to create an RSS or Atom feed for my custom built blog with CI, however whenever I try to output the xml version in the view, it always results in errors.

I'm using the following code.

Code:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

I am getting this back in Opera, and the page will not even load in Firefox.

Code:
<?xml version="1.0" encoding="UTF-8"; ?>

Everything seems to work if I remove the echo XML line, however I believe this will make the page invalid. I've read Derek Allard's blog post on creating RSS feeds and the exact same issue comes up.

I'm using the latest CI from the main site, everything else is working flawlessly and has made such a vast improvement over my previous attempts at anything like this with Zend Framework, however I just cannot seem to get this XML issue sorted.

Can anyone help me please?

Cheers
Adam
#2

[eluser]xwero[/eluser]
are the short_tags on, on your server?
#3

[eluser]Boardy[/eluser]
Hi xwero,

Short tags are not enabled on my servers. I don't like using them just to make sure all my code is useable on any server.

Cheers
Adam
#4

[eluser]xwero[/eluser]
Why do you have to echo the xml tag? Can't you just add the tag to your view file?
#5

[eluser]Boardy[/eluser]
I have tried doing that, but for some reason I get errors also. I have it working currently by assigning the ? to a variable and then echoing the variable. It's not a great solution but it's working for now.

Adam
#6

[eluser]Colin Williams[/eluser]
The fact that errors are being caused indicates short tags are on.
#7

[eluser]Murodese[/eluser]
<&lt;??&gt;?xml
#8

[eluser]attos[/eluser]
It's not a CI issue, but PHP's

I use the following in the view (Note the source where I found the fix):

Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// FROM: http://en.wikibooks.org/wiki/Programming:Complete_PHP/Escaping_from_HTML
echo "&lt;?xml version=\"1.0\" encoding=\"utf-8\" \x3F>\n"
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB