I am running the following PHP curl command:
curl_setopt($curl, CURLOPT_URL, "https://my-api-endpoint");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_USERPWD, "sec1:sec2");
$response = curl_exec($curl);
curl_close($curl);
echo $response;
That works perfectly and $response
is populated with the following XML:
[a bunch of xml before]<status>queued</status>[a bunch of xml after]
Now I'm looking for the existence of <status>queued</status>
in the string, thusly:
die("pos: " . strpos($response, "<status>queued</status>"));
Result: pos:
- note: no number displays, just nothing. This indicates that the needle was not found in the haystack.
Now I can take the string that populates $response
and hardcode it into my strpos
like this:
die("pos: " . strpos("[a bunch of xml before]<status>queued</status>[a bunch of xml after]", "<status>queued</status>"));
Result: pos: 132
- note: an int
is returned as expected. I am literally copy/pasting the value from $response
into the strpos
evaluation and getting a different result compared with evaluating the variable at runtime. I have also tried setting a variable to the returned string (thus hardcoding it into a variable instead of directly into the strpos
) instead of placing the variable inside strpos
, and again it returns the expected position int. At runtime (actual execution) it doesn't find it. But if I capture the value and hardcode a test, it DOES find it!
Here is the XML displayed in Chrome dev tools, so you can see there is no HTML-encoding going on, and in fact the string I'm looking for is there:
This is making me lose my mind. What am I missing?