0

Some Background info: My web application stores some XML in a Text column of the MySQL database. This XML represents a transaction for the application.


The problem occurs when I'm testing my library. Within PHP, I have a string:

$s="<flist><transaction amount=\"10\" type=\"income\">Initial Amount</transaction></flist>";

However, whenever I echo or consecrate this string, it turns into "Initial Amount". Am I missing a feature of PHP? How can I fix this? Wow! As I'm creating this post, StackOverflow is transforming that XML into $s=Initial Amount as well... Please help... Thank-you for your time as this completely perplexes me.

3
  • In your browser, have you tried clicking on "View Source"? Commented Jun 12, 2010 at 5:41
  • it's HTML dude. It's HTML parses your tags. Go figure Commented Jun 12, 2010 at 5:49
  • I assumed surrounding it with pre tags would have prevented that, but yes, that was the issue. Commented Jun 12, 2010 at 5:51

1 Answer 1

3

PHP doesn't automatically parse the string.

Are you echoing it and viewing it in a browser? It's very likely that the browser skips over the unknown tags and shows what it can. You might want to considering adding in htmlspecialchars() to your output like so:

echo htmlspecialchars($s);

You should also see it correctly when viewing the web source. This is a feature of HTML to support future versions without breaking current ones.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow; that was it. I feel dumb... I thought surrounding it with pre tags would stop that. That was the problem. Thank-you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.