ID:               41980
 Updated by:       [EMAIL PROTECTED]
 Reported By:      borys dot forytarz at gmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         DOM XML related
 Operating System: Linux
 PHP Version:      5.2.0
 New Comment:

Please figure out what's wrong with your file first before reporting
any bugs.


Previous Comments:
------------------------------------------------------------------------

[2007-07-12 21:05:21] borys dot forytarz at gmail dot com

I have also figured out, that if I add in content.tpl:

<meta http-equiv="content-type" content="text/html; charset=iso-8859-2"
/>

before <content> then I have polish characters. But what is strange, if
I set:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

I don't have them again. The most strange thing is that main.tpl has

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

and those characters from this file are displayed correctly. The server
also sends HTTP header that tells browser that the content is in utf-8.

And if I change it in main.tpl to:

<meta http-equiv="content-type" content="text/html; charset=iso-8859-2"
/>

I don't have those characters again.

------------------------------------------------------------------------

[2007-07-12 20:48:10] borys dot forytarz at gmail dot com

I have checked about files encodings.

mb_detect_encoding() returns, that they are ASCII-encoded (!?). So I
wrote a simple script to convert them to utf-8:

<?php
$cont = file_get_contents('login.php.tpl');
$f = fopen('login.php.tpl','w');
echo "\n".mb_detect_encoding('login.php.tpl').' > ';
fwrite($f,mb_convert_encoding($cont,'utf-8'));
echo mb_detect_encoding('login.php.tpl')."\n";
fclose($f);
?>

and the output is: ASCII > ASCII (I expected ASCII > UTF-8)

result of using iconv instead of mb_convert_encoding is the same

what's going on?

------------------------------------------------------------------------

[2007-07-12 20:38:33] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi



------------------------------------------------------------------------

[2007-07-12 19:58:58] borys dot forytarz at gmail dot com

there should be:

...
foreach($content->childNodes as $child) {
...

sorry

------------------------------------------------------------------------

[2007-07-12 19:55:58] borys dot forytarz at gmail dot com

Here is an example:

At first, source files (both encoded with UTF-8)

First file (main.tpl):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html>

<head>
        <title>Some title</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>

<body>
Some polish letters: &#281; ó &#261; &#347; &#263; &#380; &#378; &#324;
- they are encoded correctly and displays correctly.
</body>
</html>

Second file (contents.tpl):

<content>
<h1>some polish letters, like: &#281; ó &#322; &#261; &#347; &#263;
&#378; &#324; &#380; - they are not encoded correctly and does not
display correctly.</h1>
</content>



PHP file:
<?php
$dom = new DOMDocument('1.0','UTF-8');
$dom->loadHtmlFile('main.tpl');

$dom2 = new DOMDocument('1.0','UTF-8');
$dom2->loadHTMLFile('contents.tpl');

$contents = $dom2->getElementsByTagName('content');
$body = $dom->getElementsByTagName('body')->items(0);

foreach($contents as $content) {
    foreach($content as $child) {
        $imp = $dom->importNode($child,true);
        $body->appendChild($imp);
    }
}

$dom->saveXML();
?>

It is something like above. I was writing from memory because the real
script is really huge. But it demonstrates the idea and what is going
not properly.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/41980

-- 
Edit this bug report at http://bugs.php.net/?id=41980&edit=1

Reply via email to