Ok so I'm sure there's a super simple solution for this, but I have to generate a string to use to grab a json file. I know I should be using & amp; instead of &, but for some reason it's not working for me. My problem is I'm getting ¤ when trying to create my string:
$apistr = 'https://remitradar.com/JsonRequests.aspx?action=getOnlineQuotes&companyKey='.$companyKey.'&countryFrom='.$countryFrom.'&countryTo='.$countryTo.'¤cyFrom='.$currencyFrom.'¤cyTo='.$currencyTo.'&amount='.$amount;
It's spitting out:
https://remitradar.com/JsonRequests.aspx?action=getOnlineQuotes&companyKey=23e9b66aspp6z&countryFrom=AU&countryTo=FJ¤cyFrom=AUD¤cyTo=FJD&amount=200
Instead of:
https://remitradar.com/JsonRequests.aspx?action=getOnlineQuotes&companyKey=23e9b66aspp6z&countryFrom=AU&countryTo=FJ&CurrencyFrom=AUD&CurrencyTo=FJD&amount=200
Any help would be great.
Edit:
This is the var_dump of the variables and the url:
string(13) "23e9b66aspp6z"
string(2) "AU"
string(2) "FJ"
string(3) "AUD"
string(3) "FJD"
string(3) "200"
string(159) "https://remitradar.com/JsonRequests.aspx?action=getOnlineQuotes&companyKey=23e9b66aspp6z&countryFrom=AU&countryTo=FJ¤cyFrom=AUD¤cyTo=FJD&amount=200"
You should urlencode the content of the variables:
$apistr = 'https://remitradar.com/JsonRequests.aspx?action=getOnlineQuotes&companyKey='.urlencode($companyKey).'&countryFrom='.urlencode($countryFrom).'&countryTo='.urlencode($countryTo).'¤cyFrom='.urlencode($currencyFrom).'¤cyTo='.urlencode($currencyTo).'&amount='.urlencode($amount);
Than it may also get more clear if there is content in them you did not expect.
And no, you should not use & to code an & in the url.
To check the contents of the variables you may do:
var_dump($companyKey);
var_dump($countryFrom);
var_dump($countryTo);
var_dump($currencyFrom);
var_dump($currencyTo);
var_dump($amount);
var_dump($apistr);
If you echo the content of $apistr to your webbrowser ¤
will be displayed as the currency glyph ¤
as the html entity ¤ is reserved.
Try to echo it this way to your browser instead (but dont use this as url! The variable $apistr contains what you expect - only the debug echo output was wrong in case of the rendering of your browser):
echo htmlspecialchars($apistr);
When ever you just output a string of characters your rendering application is your webbrowser. You also may look at the sourcecode of the webside containing the presumed wrong url. You should see the correct characters in the source. The output of htmlspecialchars($apistr);
however would be look wrong in the source code but correct in the rendered webpage.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments