sKunKbad Posted July 10, 2009 Share Posted July 10, 2009 I'm trying to check for an error message within some XML that is returned from cURL, but strstr and strpos aren't working for me: <?php $response ="<?xml version='1.0' encoding='UTF8'?><error xmlns='http://incubator.apache.org/abdera'><code>409</code><message>Email address (someemailaddress.com) is already a contact</message></error>1"; // Check for error if (strpos($response, "<?xml version='1.0' encoding='UTF8'?><error")) { echo "The subscription process failed - try again.<br />"; } echo $response; // echo response, it may contain an error message ?> What's wrong here? Instead of strstr or strpos seeing my needle in the haystack, I just see the haystack output. Link to comment https://forums.phpfreaks.com/topic/165546-strpos-and-xml/ Share on other sites More sharing options...
thebadbad Posted July 10, 2009 Share Posted July 10, 2009 The needle is found at position 0, evaluating to false. That's why you always use strict comparison when checking the return of strpos(). if (strpos($response, "<?xml version='1.0' encoding='UTF8'?><error") !== false) Link to comment https://forums.phpfreaks.com/topic/165546-strpos-and-xml/#findComment-873201 Share on other sites More sharing options...
sKunKbad Posted July 11, 2009 Author Share Posted July 11, 2009 Well, I figured that out, but the problem is that the real haystack is XML being brought in from cURL, and it just isn't acting the same as when the haystack is in the code as I showed. I think it has more to do with cURL than strpos. Link to comment https://forums.phpfreaks.com/topic/165546-strpos-and-xml/#findComment-873287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.