#47734 [Opn->Fbk]: simple_xml_load string fails without error message when encooding broken

From: Date: Wed, 01 Apr 2009 11:38:27 +0000
Subject: #47734 [Opn->Fbk]: simple_xml_load string fails without error message when encooding broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-135434@lists.php.net to get a copy of this message
ID: 47734 Updated by: jani@php.net Reported By: cupidle at gmx dot de -Status: Open +Status: Feedback Bug Type: SimpleXML related Operating System: WinXP SP2 PHP Version: 5.2.9 New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Previous Comments: ------------------------------------------------------------------------ [2009-03-20 16:54:27] cupidle at gmx dot de Description: ------------ When simplexml_load_string fails loading xml it returns FALSE. An error message should be available via error_get_last. This is not the case when certain encoding errors are encountered. Reproduce code: --------------- I'm using this code to gracefully fall back on encoding errors: $xml = simplexml_load_string($data); // character encoding warning- hack if ($xml === false) { $error = error_get_last(); // this is nasty- sometimes simplexml_load_string fails but doesn't raise an error # if (eregi('simplexml_load_string', $error['message'])) { $xml = simplexml_load_string(utf8_encode($data)); } } Expected result: ---------------- This does _sometimes_ work (i.e. call the innermost, encoded version), but not always. For example, simplexml_load_string silently fails without error message when processing data from amazon like this: http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Version=2007-12-24&Operation=ItemSearch&AssociateTag=cpuidle-20&AWSAccessKeyId=1CB01P12WQBRDNH10NR2&ItemPage=1&Keywords=Star+Wars%3A+Episode+1& Actual result: -------------- simplexml_load_string returns FALSE, but does not return error message. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47734&edit=1

« previous php.bugs (#135434) next »