PHP generated XML shows invalid Char value 27 message
A useful function to get rid of that error is suggested on this website.
http://www.phpwact.org/php/i18n/charsets#common_problem_areas_with_utf-8
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 such as above
function utf8_for_xml($string)
{
return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
}
Hope that saves someone else some time..
XML Error: Invalid character
Make sure the web server you're pulling the file from is sending the correct character encoding when it serves the page. You should see something like this in the response headers:
Content-Type:"text/xml; charset=utf-8"
The headers can be viewed in the network panel of the inspector in any modern browser, when you request the XML file directly.
You should also specify the encoding in the file itself. The first line should look something like this:
<?xml encoding='UTF-8'?>
If these fail, you can always try using utf8_decode()
which is an XML_Parser function that will attempt to convert the data to iso-8859-1.
Failed loading XML:xmlParseCharRef: invalid xmlChar value
XML has no notion of HTML entities. As a hack, you can decode the entities first with
$html = html_entity_decode($file_contents, ENT_QUOTES, "utf-8");
and then try parse $html
with the XML parser. Just hope it's tolerant enough, because HTML is still not valid XML.
The good news is that you can then remove the if (strstr("&",
hack because that is taken care of by html_entity_decode()
.
PHP invalid character error
Simply you can not use an element name start with number
1OhmStable <-- rename this
_1OhmStable <-- this is fine
php parse xml - error: StartTag: invalid element name
A nice article :- http://www.xml.com/pub/a/2001/07/25/namingparts.html
A Name is a token beginning with a letter or one of a few punctuation characters, and continuing with letters, digits, hyphens, underscores, colons, or full stops, together known as name characters.
Related Topics
PHP Mail Special Characters Utf8
Changing Woocommerce Cart Item Names
Double Results in My Array ( MySQL_Fetch_Array )
Replace Only First Match Using Preg_Replace
What Causes an Http 405 "Invalid Method (Http Verb)" Error When Posting a Form to PHP on Iis
What Does the B in Front of String Literals Do
Get Root Node of Xml Doc Using Simplexml
Is PHP's 'Include' a Function or a Statement
Change Date Format (In Db or Output) to Dd/Mm/Yyyy - PHP MySQL
Sent Mails with PHPmailer Don't Go to "Sent" Imap Folder
What Is the "" Symbol in Url Used for in PHP
Change Single Variable Value in Querystring
Function Eregi() Is Deprecated
Display Output in Parts in PHP
Using Regex to Filter Attributes in Xpath with PHP
Reflectionexception: Class Classname Does Not Exist - Laravel