tags:

views:

92

answers:

5

When I add the string below to an array in PHP and output it,

$spineArray[$i]="<itemref idref='part-$i' linear='yes'/>";

It looks like this when outputted. Why is the closing tag automatically added and can I stop it? Thanks.

<itemref idref='part-$i' linear='yes'> </itemref>
+15  A: 

I can assure you that PHP doesn't do this - at least, not by itself. Where are you looking when you see the output you describe?

Chances are that whatever you're using to view the output in is not showing the raw output, but the result of it parsing the XML you give it, but without some more information, I'm afraid your question cannot be answered.

kander
Hi, I'm using firebug to check it
usertest
Your browser or whatever you are using to view the output might be putting the end tag there. As others have said, PHP will just echo what you ask it to.
NullUserException
That's the culprit - firebug doesn't show you what PHP generated, it shows you a representation of the DOM tree as the browser has it while displaying your page. Use the old-school "View Source" option to see the output as it truly is.
kander
@user201140: firebug show you dynamic DOM with all html errors corrected
Ankit Jain
A: 

What do you use to process and output it? There must be some HTML/XML processing tool in the way because PHP itself doesn't do this.

The answer is to remove the HTML/XML processing or keep a copy of the string in another variable and output that one.

dark_charlie
A: 

Based on your paste, I assume you are viewing this in some sort of XML viewer. It's possible for the XML to be displayed this way.

Brad
+4  A: 

Are you using FireBug to look at the HTML? Firebugs adds missing tags on it's own. Make sure that you look at the HTML with the browser's "View Source" feature

edit: Your replay to kander makes it obvious. If you look at the code as described above, I'm sure you won't see the tag added.

DrColossos
Thanks, your exactly right. It difference wouldn't have mattered but there seems to be a bug in firebug that displayed my list of closed tags as nested in each other, when in fact View Source shows there now.
usertest
+1  A: 

I think you used the firefox "view selected source". It shows the interpreted/corrected/parsed state of the html. If you use "view source" (CONTROL + u) you will see the raw markup.

Try for yourself:

<p>lorem<br />ipsum</p>

In "view selected source <br /> transform to <br>":

<p>lorem<br>ipsum</p>

In "view source <br /> stays <br />":

<p>lorem<br />ipsum</p>
Benjamin Cremer