0

I'm programming a function to build an URL, here it is :

public static function requestContent($p_lParameters)
{
    $sParameters = "?key=TEST&format=json&jsoncallback=none";

    foreach($p_lParameters as $sParameterName => $sParameterValue)
    {
        $sParameters .= "&$sParameterName=$sParameterValue";
    }

    echo "<span style='font-size: 16px;'>URL : http://api.oodle.com/api/v2/listings" . $sParameters . "</span><br />";

    $aXMLData = file_get_contents("http://api.oodle.com/api/v2/listings" . $sParameters);

    return json_decode($aXMLData,true);
}

And I am calling this function with this array list :

print_r() result : Array ( [region] => canada [category] => housing/sale/home )

But this is very strange I get an unexpected character (note the special character none**®**ion) :

http://api.oodle.com/api/v2/listings?key=TEST&format=json&jsoncallback=none®ion=canada&category=housing/sale/home

For information I use this header :

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<?php header('Content-Type: text/html;charset=UTF-8'); ?>

EDIT :

$sRequest = "http://api.oodle.com/api/v2/listings?key=TEST&format=json&jsoncallback=none&region=canada&category=housing/sale/home";

echo "<span style='font-size: 16px;'>URL : " . $sRequest . "</span><br />";

return the exact URL with problem :

http://api.oodle.com/api/v2/listings?key=TEST&format=json&jsoncallback=none®ion=canada&category=housing/sale/home
13
  • wow its taking your &reg(from region) to html for register which is &reg
    – Dinesh
    Nov 19, 2012 at 4:31
  • Yes but there is no ; at the end.... Nov 19, 2012 at 4:32
  • can you check what happens when you do utf8_encode($aXMLData) .. this will encodes an ISO-8859-1 string to UTF-8.
    – Dinesh
    Nov 19, 2012 at 4:36
  • I agree thats y I am shocked.. it was still taking it as ascii value..
    – Dinesh
    Nov 19, 2012 at 4:38
  • 1
    People get so exited about answering the question that they forget the idea is to think about correct answer.. I just got carried away..
    – Dinesh
    Nov 19, 2012 at 4:58

2 Answers 2

1

here is the solution and this time it will work

$sParameters .= "&$sParameterName=$sParameterValue";
$sParameters = htmlentities($sParameters);

It converts all the charset into html code.. totally forgot about this even when I regualarly use it in user input...

0
0

Well, first you build a string

$sParameters = "?key=TEST&format=json&jsoncallback=none";

And then you're appending to that. So it will concatenate. Now, the last part of a string might be & and your parameter is region.

Somehow that gets converted to the html ASCII code &reg; which causes the registered symbol to appear.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.