473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Xml, Accents and php domxml_open_file

Hi everybody,
I have xml documents with external entities for my accents that I
want to output properly with php function domxml_open_file. I can't get
my accents on a linux-apache server (I get "é" instead of "é"). My
browser is IE6. Do you know why ? A strange thing is that the very same
script on the same document works fine on a windows-apache server.

My xml document :
<?xml version="1.0" ?>
<!DOCTYPE survey [
<!ENTITY eacute "é"> ]>
<survey>
<dict l="fr">
<q id="1" mnemo="cible" type="1" nbmod="7">
<lib>here is an accent &eacute; </lib>
</q>
</dict>
</survey>
My php script :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<meta name="GENERATOR" content="Quanta Plus">
</head>
<body>
<?
if (!$dom = domxml_open_file($fileEtude)) {
echo "Impossible de charger l'&eacute;tude dans le DOM\n";
exit;
}
$root = $dom->document_element();
$domDict = $root->get_elements_by_tagname("dict");
$ArrQ = $root->get_elements_by_tagname("q");
$CurQ = $ArrQ[0];
$NodeLib = array_shift($CurQ->get_elements_by_tagname("lib"));
echo $NodeLib->get_content();
?>

Thanks in advance,
Ghislain


Jul 20 '05 #1
2 8395


Ghislain Benrais wrote:
Hi everybody,
I have xml documents with external entities for my accents that I
want to output properly with php function domxml_open_file. I can't get
my accents on a linux-apache server (I get "é" instead of "é"). My
browser is IE6. Do you know why ? A strange thing is that the very same
script on the same document works fine on a windows-apache server.


I think you are not encountering any XML problems but rather PHP
shortcomings. The encodings meant to be used with XML, for instance
UTF-8, are much more powerful than PHP's string handling capabilities
which only allow for 8-bit strings. So while PHP has some XML
capabilities you run easily into problems with any characters not in ASCII.
However PHP has some functions to convert UTF-8 to ISO-8859-1 and back
so french accents shouldn't cause a problem as they are in ISO-8859-1.
Thus if you encode your XML as UTF-8 as in

<?xml version="1.0" encoding="UTF-8"?>
<sentence xml:lang="fr">Je suis fatigué.</sentence>

then you should use PHP's utf8_decode function to convert to ISO-8859-1:

<html>
<head>
<title>Testing PHP's W3C DOM support</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
<?php
if (!$xmlDocument = domxml_open_file("test20031011.xml")) {
echo "Error parsing XML document.<br>";
exit;
}
else {
$rootElement = $xmlDocument->document_element();
$firstChild = $rootElement->first_child();
echo "firstChild.node_type(): " . $firstChild->node_type() . "<br>";
echo "firstChild.node_value(): " .
utf8_decode($firstChild->node_value()) . "<br>";
}
?>
</p>
</body>
</html>

That way the accents should display properly in the browser.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Thank you Martin, it works just perfectly fine thanks to your
explanations.By the way, I don't use utf8_decode but charset="UTF-8" in
the header so that it works fine on both windows and linux server.
<?xml version="1.0" encoding="UTF-8"?>
<conclusion xml:lang="fr">Je ne suis plus fatigué et à la
prochaine.</conclusion>
Martin Honnen wrote:


Ghislain Benrais wrote:
Hi everybody,
I have xml documents with external entities for my accents that I
want to output properly with php function domxml_open_file. I can't get
my accents on a linux-apache server (I get "é" instead of "é"). My
browser is IE6. Do you know why ? A strange thing is that the very same
script on the same document works fine on a windows-apache server.

I think you are not encountering any XML problems but rather PHP
shortcomings. The encodings meant to be used with XML, for instance
UTF-8, are much more powerful than PHP's string handling capabilities
which only allow for 8-bit strings. So while PHP has some XML
capabilities you run easily into problems with any characters not in ASCII.
However PHP has some functions to convert UTF-8 to ISO-8859-1 and back
so french accents shouldn't cause a problem as they are in ISO-8859-1.
Thus if you encode your XML as UTF-8 as in

<?xml version="1.0" encoding="UTF-8"?>
<sentence xml:lang="fr">Je suis fatigué.</sentence>

then you should use PHP's utf8_decode function to convert to ISO-8859-1:

<html>
<head>
<title>Testing PHP's W3C DOM support</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
<?php
if (!$xmlDocument = domxml_open_file("test20031011.xml")) {
echo "Error parsing XML document.<br>";
exit;
}
else {
$rootElement = $xmlDocument->document_element();
$firstChild = $rootElement->first_child();
echo "firstChild.node_type(): " . $firstChild->node_type() . "<br>";
echo "firstChild.node_value(): " .
utf8_decode($firstChild->node_value()) . "<br>";
}
?>
</p>
</body>
</html>

That way the accents should display properly in the browser.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: chepiok | last post by:
I'd like to send email containing accents (french one) using PHP command mail(). The content of these emails are store in text files. I'de like to know : - text file format (encoding, with...
2
by: Thekave | last post by:
This function return always an error: if (!$dom = domxml_open_file("test.xml")) { Warning: failed to load external entity "test.xml" in c:\programmi\apache group\apache\test\op1.php on line 9...
2
by: c w | last post by:
Can anyone point me in the right direction? Using Oracle 9i, Pro*C and Excel. I am trying to print french accents from the Oracle DB using Pro*C to extract the necessary info and sent the result...
0
by: Wim Roffal | last post by:
When I sort texts with accents the accents end up in the end instead of near the same text without accent. For example, the 3 composers Händel, Haydn and Holst will appear in the order Haydn,...
2
by: Michael Strorm | last post by:
Hi, I'm using PHP 4.3.9 with Apache 2.0, and keep getting the error " PHP Fatal error: Call to undefined function: domxml_open_file() in /var/www/html/php/domtest.php on line 8" (from the...
0
by: Chris Leffer | last post by:
Hi. I am having problems to use HtmlEncode with strings that use accents. My page uses some expressions like that: <%# Server.HtmlEncode(DataBinder.Eval(Container.DataItem, "Name").Trim) %> ...
1
by: Paul | last post by:
alllow_url_fopen if set to off. For some reason I can not access domxml_open_file(). And I need to read an xml feed. I can access the feed using cURL: $feed =...
1
by: bssjohn | last post by:
Dear All, I have developing a French website using PHP & Ajax. In that I tried to display some French texts from mysql database using Ajax. Form local I got the text from db with Correct accents...
5
by: arty | last post by:
i have set up a xhr , all the accents on the page are showed ok on ff an safari function _cms() { cms.open("GET", 'cms.php', true); cms.setRequestHeader('If-Modified-Since','Wed, 05 Apr 2006...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.