$account_info['descriptiveName'] - string is not in UTF-8 error - php

25 views
Skip to first unread message

Richard Hassall

unread,
Jan 22, 2009, 7:18:52 AM1/22/09
to adwor...@googlegroups.com
Hi all

I am having a problem with an error. The error is:

Warning: DOMDocument::save() [domdocument.save]: string is not in UTF-8 in C:\wamp\www\xxx\xxx\xxx\xxx\get_all_campaigns.php on line 44

the line in question = $doc->save($xml_file_name);

'$xml_file_name' is created via an include, which gets all required data from Google and outputs to xml.

$xml_file_name = "\\\\xxx\xxx\\" . $refrence . ".xml";

Have also tried: 
$xml_file_name = "\\xxx\xxx\" . $refrence . ".xml";
$xml_file_name = "//xxx/xxx/" . $refrence . ".xml";
and also using single quotes

'$refrence' is obtained by doing the following:

$refrence_x = preg_replace('/(........).*()/','$1',$account_info['descriptiveName']);
$refrencer_x = str_replace($special,"_",$refrence_x);
$refrence = $refrence_x;

(the above basically gets the 1st 8 characters of '$account_info['descriptiveName']', then replaces any spaces with underscores, then stores it in '$refrence')

The script, loops through about 30 accounts x 4 client manager accounts, getting all of the required information and outputting to xml files.

This error only occurs once for one account manager and it is always the same account, which makes me think that it is something to do with '$account_info['descriptiveName']' as this is the only unique constant.

I have tried:

$xml_file_name = utf8_encode($xml_file_name);

But I still get the error. Has anyone else come across this or have any ideas. The file saves no problem as fas as I can tell but I need to get rid of the warning message, ideally without turning off error reporting


AdWords API Advisor

unread,
Jan 22, 2009, 4:21:25 PM1/22/09
to AdWords API Forum
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
Reply all
Reply to author
Forward
0 new messages