PHP5 DOMDocument: specifying encoding programmatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin McGuigan

    PHP5 DOMDocument: specifying encoding programmatically

    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
Working...