php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41484 DOMDocument doesn`t convert character-set automaticly
Submitted: 2007-05-24 08:54 UTC Modified: 2007-05-24 09:25 UTC
From: songqi at baidu dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.2 OS: Redhat linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: songqi at baidu dot com
New email:
PHP Version: OS:

 

 [2007-05-24 08:54 UTC] songqi at baidu dot com
Description:
------------
I want to use DOM Functions to generate xml with some gb2312 characters, but DOMDocument doesn`t convert character-set to utf-8 automaticly, and throws a exception 'DOMException' with message 'Invalid Character Error'.

Reproduce code:
---------------
$doc = new DOMDocument("1.0","gb2312");
$doc->createElement("?ؼ???");
echo $doc->saveXML();

Expected result:
----------------
<?xml version="1.0" encoding="gb2312"?>
<?ؼ???/>

Actual result:
--------------
Fatal error: Uncaught exception 'DOMException' with message 'Invalid Character Error' in /home/songq/local/htdocs/test/Auth.php:7 Stack trace: #0 /home/songq/local/htdocs/test/Auth.php(7): DOMDocument->createElement('??????') #1 {main} thrown in /home/songq/local/htdocs/test/Auth.php on line 7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-24 09:25 UTC] chregu@php.net
$doc->createElement("") and all other DOM methods (except the ->load..() 
methods) always expects UTF-8 encoded strings

That's how it works. Not a bug.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 11:02:27 2025 UTC