2

I am generating XML dynamically. There may be arbitrary data which is entered by users. Which characters do I have to encode in order to show them properly in the XML file?

I am using PHP.

3
  • <>'"& are the 'Big 5'. htmlspecialchars() will do this for you automatically. Commented Jul 21, 2011 at 19:01
  • You need ENT_QUOTES as well to encode the ''s. Otherwise it just encode's <>"& Commented Jul 21, 2011 at 19:03
  • htmlspecialchars('asfa<>sf') shows me asfa<>sf. No encoding. Any help? Commented Jul 21, 2011 at 19:05

1 Answer 1

2
htmlspecialchars($string, ENT_QUOTES);
Sign up to request clarification or add additional context in comments.

2 Comments

echo htmlspecialchars("asfa<>sf", ENT_QUOTES); gived me asfa<>sf. Is it encoded?
@elbek htmlspecialchars encodes those characters so that they look the same as they were meant to in a browser, but don't function the same in XML or HTML. it encodes < as &lt; for example, and a web browser renders &lt; as < w ithout it having the meaning it does in XML

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.