php prevent & creating codes in a string

Leanne Seawright

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.'&currencyFrom='.$currencyFrom.'&currencyTo='.$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" 
cmks

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).'&currencyFrom='.urlencode($currencyFrom).'&currencyTo='.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 &curren 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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Prevent creating duplicate entries in PHP

From Dev

Trouble creating a PHP string

From Dev

How to convert string to HTML codes in php laravel?

From Dev

PHP remove terminal codes from string

From Dev

PHP regex prevent repeated string

From Dev

Creating custom status codes

From Dev

Creating an XML string from php string

From Dev

how to show article comment contains (php codes) as string

From Dev

Creating XML string with multiple items in PHP

From Dev

String formatting type codes

From Dev

PHP codes for wordpress

From Dev

Merging PHP codes

From Dev

PHP codes of Unix in Ubuntu

From Dev

PHP - Converting codes to items

From Dev

Replacing ascii codes in php

From Dev

Running php codes on the background

From Dev

PHP codes of Unix in Ubuntu

From Dev

Always returning × instead of x in php string, how to prevent this?

From Dev

How to prevent PHP variables and expressions from expanding in string

From Dev

Php json_encode converts utf8 string to characters codes

From Dev

PHP super weird warning : illigal string offset while creating a key

From Dev

Creating String Array joining elements of 2 arrays in php

From Dev

Creating a PDO connection string from PHP class and DBMS techniques

From Dev

php algorithm for creating a list of keywords from a string of keywords

From Dev

Creating PHP class instance with a string into Symfony2

From Dev

php algorithm for creating a list of keywords from a string of keywords

From Dev

How to execute PHP code after automaticly creating it using string concatenation?

From Dev

PHP - Creating an array from a string given from an API

From Dev

Prevent application from creating a gemset

Related Related

HotTag

Archive