Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCDATA invalid Char value 31 #39

Closed
math62400 opened this issue Jan 15, 2015 · 2 comments
Closed

PCDATA invalid Char value 31 #39

math62400 opened this issue Jan 15, 2015 · 2 comments

Comments

@math62400
Copy link

First of all, thanks !!
Your tools helps me a lot for UTF8 string conversion

I would save a string in XML and I would like to format it in UTF8,
But I have this error when I try to load XML after save.

DOMDocument::load(): PCDATA invalid Char value 31

I look for an answer in Google and I found that.

http://stackoverflow.com/questions/14463573/php-simplexml-load-file-invalid-character-error

function utf8_for_xml($string)
{
    return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
}

Can you tell me if there is an other way to solve it?

Mathieu

@oxxido
Copy link

oxxido commented May 27, 2015

Hey, you probably already solve it, but this is nothing to do with utf8 (specifically):

When you put utf-8 encoded strings in a XML document you should remember that not all utf-8 valid > chars are accepted in a XML document http://www.w3.org/TR/REC-xml/#charsets
So you should strip away the unwanted chars, else you’ll have an XML fatal parsing error

from http://www.phpwact.org/php/i18n/charsets

@neitanod
Copy link
Owner

Thanks oxxido!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants