PHP: Variable not getting interpreted correctly?
I'm not really sure what question to ask because I'm not really sure what is causing it.
So here's what is happening.....
I have a function that starts off like this:
function core_stackoverflow_init($obj){
$options = $obj->options;
$options->query = (string)$options->query;
$options->query = "key=xxxxxxxxxxxxxx&answers=true&body=true&comments=true";
$fp = fsockopen("api.stackoverflow.com", 80, $errno, $errstr, 30);
if (!$fp){
echo 'Could not connect to StackOverflow'; return false;
}
$out = "GET /1.1/".$options->resource."?".$options->query." HTTP/1.1\r\n";
When I echo $options->query
for both lines 3 and 4, they echo out as the same thing, so I would think that $obj->options->query
coming in should work fine.
However, stackoverflow only gives me a full response back when I have line 4 in there (manually reassigning $options->query
). I get a response back stackoverflow, but I don't get any comments, and if I move the &body=true, to later, I don't get the body. But if I use line 4, I get everything I'm expecting.
So it's like line 3 is being terminated or being interpreted incorrectly.
$obj is formed from a json_decode()
, so I thought that maybe somehow the decode was casting it as an integer or something bizarre so that's why you see my casting the var back as a (string)....just to make sure.
I've tried urlencode()
and trim to no avail.
Are there any special characters or something you can think of that I can test to debug this?
EDIT:
When var_dumping the variables mentions there is a big difference:
string(75) "body=true&answers=true&comments开发者_JAVA百科=true&key=XXXXXXXXXXXXXXXXXXXXXX"
string(63) "key=XXXXXXXXXXXXXXXXXXXXXX&answers=true&body=true&comments=true"
So I did a trim($options->query) on the first value and go the same response.
????
Alright, I figured it out. Thanks for reminding me to var_dump.
So I did a bin2hex so I could look at the actual hex codes. It turned out the input was getting turned into html_entities from the browser.
So I did an html_entity_decode and it works.
精彩评论