|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-02-16 13:17 UTC] chregu@php.net
[2006-02-24 01:00 UTC] php-bugs at lists dot php dot net
[2006-03-21 19:15 UTC] vodka_carambar_lovely_spam at yahoo dot com
[2008-02-20 16:43 UTC] jona at oismail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 04:00:01 2025 UTC |
Description: ------------ An instance of the XSLTProcessor class, via its transformToXML method, is used to transform XML documents using an XSL stylesheet. The XSL document is in a file that is encoded in UTF-8. The PHP script is in a file also encoded in UTF-8. The XML documents are created at run time from XML strings stored in a MySQL 5 database whose character set is UTF-8 and whose tables all have UTF-8 as their character set as well. All the XML strings stored in the database are duly encoded in UTF-8. Prior to data retrieval, a 'SET NAMES "utf8"' query is run to ensure that all i/o operations use the UTF-8 character set. Upon transformation, the results are output to the client preceded by "header('Content-Type: text/html; charset=UTF-8')" to ensure that the browser uses the correct character set. The XSL file has the following top-level (child node of the document element, as it should be) element: <xsl:output encoding="utf-8" method="html"/> When this code is run on a Windows server (Win XP, Apache 2.0.55,PHP 5.1.2), the transformation NEVER outputs UTF-8 text (seems to output iso-8859-1), even if the 'method' attribute in the above element is changed to 'xml', and even if a 'media-type' attribute is also used. When run on a Linux server (also running PHP 5.1.2), the transformation runs as expected and outputs proper UTF-8 text to the browser. Reproduce code: --------------- PHP code: $dbo = new PDO(BD_DSN, BD_USERNAME, BD_PWD); $dbo->query('SET NAMES "utf8"'); $sql = 'SELECT Report FROM reports WHERE Id = '.$dbo->quote(strip_gpc_slashes($_GET['rid'])).' AND Author = '.$dbo->quote($_SESSION['user']); $result = $dbo->query($sql); $row = $result->fetch(PDO::FETCH_OBJ); $xml = new DOMDocument('1.0', 'UTF-8'); $xml->loadXML($row->Report); $xsl = new DOMDocument('1.0', 'UTF-8'); $xsl->load('/path/to/xsl/file.xsl'); $proc = new XSLTProcessor; $proc->importStyleSheet($xsl); $output = $proc->transformToXML($xml); header('Content-Type: text/html; charset=utf-8'); print $output; Start of XSL document: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2005/11/schema-for-xslt20.xsd"> <xsl:output encoding="utf-8" method="html"/> <xsl:template match="/">... Expected result: ---------------- All text output to the browser should be proper UTF-8. If the browser's character encoding is set to UTF-8 (which it should, with the "content-type" header above), all accented character should be adequately displayed. Actual result: -------------- When the code is run on a Windows XP server, the text output to the browser is NOT proper UTF-8 and all accented characters are replaced by weird symbols. When the code is run on a Linux server (also equipped with PHP 5.1.2), everything works as expected and the output is proper UTF-8.