473,657 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP5 DOMDocument: specifying encoding programmaticall y

Shorter: How do I tell DOMDocument->load() what encoding I want it to use?

Longer: I search for and process XML files from elsewhere, and need to
transform them with some XSLTs. No problem. Using PHP5 and the DOM
library, everything's a snap. Worked fine, up till now. Today, funky
characters were in the XML file -- "smart" quotes from Word, it looks
like. Anyways, DOMDocument->load complained about them, saying that
they weren't UTF-8, and to specify the encoding.

Lo and behold, the encoding is not specified in these XML files. If I
add in 'encoding="iso-8859-1"' to the header, it works fine. The rub is
I have no control over these XML files.

Reading the file into a string, modifying its header and writing it back
out to another location seems to be my only option, but I'd prefer to do
it without having to use temporary copies of the XML files at all. Is
there any way to simply tell the parser to parse them as if they were
iso-8859-1?

--Colin McGuigan
Jul 17 '05 #1
0 2340

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

Similar topics

3
2829
by: Rutger Claes | last post by:
Code and problem are from PHP5: When I execute the following piece of code, the DomException is thrown with a message: Not Found Exception. I assume this means that the node I extracted from the DomDocument using getElementsByTagName() isn't found when I use insertBefore(). I blame the namespace :-) When I replace the getElementsByTagName( 'xsl:template' ), I get the "no template tag found message" in the else. What is the NS-safe way...
3
3005
by: Philipp Lenssen | last post by:
I want to try the new Yahoo API, but I get the PHP5 error message Unknown encoding "utf-8" in the marked line below... (After that, applying the Xpath will fail as symptom of the first bug.) function showImages($q) {
1
2762
by: dk_sz | last post by:
Is it just me... Or is PHP5 XML very limited? Or am I missing something very obvious? Any way to use PHP4 Dom XML in PHP5? Does anyone know why support for it was dropped? I have following code I need to have replaced: PHP4
2
1913
by: dk_sz | last post by:
Can anyone point me to a guide or something for conversion? I tryed http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/index.en.html but it doesn't work (not all parts anyway) - and as I can't find a working IDE/debugger combination I can't currently figure out why. I need to translate following code:
2
3124
by: al3x4nder | last post by:
I`m need hanling XSLT errors in my script, before I`m use Sablotron, that has nice interface for it: ------------8<------------------ function ProduceXHTML($xml, $xsl){ $xh = xslt_create(); xslt_set_encoding ($xh, CODE_PAGE); $arguments = array('/_xml' => $xml, '/_xsl' => $xsl); $result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
2
9124
by: JÿGius³ vs ::NRG::ius | last post by:
Hi all. I have this script ----------------------------------------------------------- <?php $doc = new DOMDocument(); $doc->load('books.xml'); echo $doc->saveXML(); ?>
0
1335
by: R | last post by:
Hi All, I've run into very disturbing problem, I must use html tags inside one of my XML node so I wrote: $cdataHelp = $DomDocument->createCDATASection($value); when I dump it as XML
2
2272
by: mananvyas | last post by:
Hi, I am working on PHP5 and all the xmldom related extensions are installed and on properly. I am trying to execute following code but some how not working. $doc = new DomDocument(); $doc->validateOnParse = true; $doc->load('abc.xml');
2
5277
by: eltower | last post by:
adactio.com/journal/1202 has a very interesting PHP script which gathers RSS data from various feeds and prints them in an HTML table. He calls this a lifestream. Anyways, unfortunately, my knowledge of PHP is rather limited - I'd rather work with a stylesheet. It turns out that my local machine has PHP5, and the script works flawlessly. However, Bluehost, my hosting provider, has PHP 4.4.4. As a result, I'm getting a lot of exceptions...
0
8303
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8602
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7316
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.