Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 875889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:20:50+00:00 2026-05-15T11:20:50+00:00

Is there any function that I can use to parse any string to ensure

  • 0

Is there any function that I can use to parse any string to ensure it won’t cause xml parsing problems? I have a php script outputting a xml file with content obtained from forms.

The thing is, apart from the usual string checks from a php form, some of the user text causes xml parsing errors. I’m facing this “’” in particular. This is the error I’m getting Entity 'rsquo' not defined

Does anyone have any experience in encoding text for xml output?

Thank you!


Some clarification:
I’m outputting content from forms in a xml file, which is subsequently parsed by javascript.

I process all form inputs with: htmlentities(trim($_POST['content']), ENT_QUOTES, 'UTF-8');

When I want to output this content into a xml file, how should I encode it such that it won’t throw up xml parsing errors?

So far the following 2 solutions work:

1) echo '<content><![CDATA['.$content.']]></content>';

2) echo '<content>'.htmlspecialchars(html_entity_decode($content, ENT_QUOTES, 'UTF-8'),ENT_QUOTES, 'UTF-8').'</content>'."\n";

Are the above 2 solutions safe? Which is better?

Thanks, sorry for not providing this information earlier.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:20:51+00:00Added an answer on May 15, 2026 at 11:20 am

    You take it the wrong way – don’t look for a parser which doesn’t give you errors. Instead try to have a well-formed xml.

    How did you get &rsquo; from the user? If he literally typed it in, you are not processing the input correctly – for example you should escape & to &amp;. If it is you who put the entity there (perhaps in place of some apostrophe), either define it in DTD (<!ENTITY rsquo "&x2019;">) or write it using a numeric notation (&#x2019;), because almost every of the named entities are a part of HTML. XML defines only a few basic ones, as Gumbo pointed out.

    EDIT based on additions to the question:

    • In #1, you escape the content in the way that if user types in ]]> <°)))><, you have a problem.
    • In #2, you are doing the encoding and decoding which result in the original value of the $content. the decoding should not be necessary (if you don’t expect users to post values like &amp; which should be interpreted like &).

    If you use htmlspecialchars() with ENT_QUOTES, it should be ok, but see how Drupal does it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any opencv function like cvHoughCircles() that can use for square detection programming
Is there any javascript function that can encrypt data: For example i want to
Is there any way that I can call a JavaScript function via css? For
I have a javascript function that checks for a date range. Is there any
Is there any function that does the inverse operation of array_diff() ? I mean,
Is there any function that do the opposite job of QString::split() . I mean
Is there any equivalent function that returns the character at position X in PHP?
is there any function in C++ that calculates a fingerprint or hash of a
Is there any already implemented function that has initialArray, sizeOfInitialArray, outArray, and sizeOfOutArray parameters,
Is there any function in haskell libraries that sorts integers in O(n) time?? [By,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.