Hello Richard,
(The standard I'm-not-a-PHP-UTF-8-expert disclaimer, which I've been
making a lot recently, applies.)
I guess it's possible that the actual string in $xml_file_name has a
bad encoding, but that doesn't sound too likely. To rule that out, why
don't you try hardcoding a file name (plus a counter if it needs to be
unique) and see if the problem persists?
I'd think that it's much more likely that the XML library you're
using is complaining about the content of the XML string you're trying
to write to a file, not the file name. If you're manipulating the XML
before your write it to disk, are you sure that the act of replacing
text isn't converting the content of the XML into a format other than
UTF-8, or inserting characters that aren't valid in UTF-8? I'd be kind
of surprised if the XML library would let you edit the in-memory
representation of the DOM in such a way that the character encoding
changed, but that's my best guess.
You might want to isolate this issue into its smallest reproducible
case and post in a general PHP discussion forum too, because I don't
think there's anything specific to the AdWords API that is causing the
behavior you're describing.
Cheers,
-Jeff Posnick, AdWords API Team