I am using implode to create a query string but there is an unexpected symbol appearing in it and im unsure where it is coming from
If anyone has any insight it would be much appreciated.
$url = "https://mypay.com/billing/signup.cgi";
$key = "11";
$key .= "11";
$key .= "GBP";
$key .= "QQDNfAHlC2WEEfhfhFFdhbdf";
$variables[] = "?formDigest=".md5($key);
$variables[] = "clientAccnum=1111";
$variables[] = "clientSubacc=1111";
$variables[] = "formName=108ck";
$variables[] = "formPrice=11";
$variables[] = "formPeriod=11";
$variables[] = "currencyCode=GBP";
$url .= implode("&", $variables);
echo $url;
The String
https://bill.ccbill.com/jpost/signup.cgi?formDigest=df03f2b103f79bd5de34c6cfea405ec5&clientAccnum=1111&clientSubacc=1111&formName=108ck&formPrice=11&formPeriod=11¤cyCode=GBP
notice the ¤ symbol where currencyCode should be.
Thanks for the help guys!
implodeworks fine.The problem here is that you are outputting HTML text (
echo $url) but you are not properly encoding HTML special characters withhtmlspecialchars.When the browser sees the substring
¤cyCode=GBPit guesses that you must have meant¤Code=GBP;¤is the HTML entity for the currency symbol, so that’s what you see on the screen.Change the code to
echo htmlspecialchars($url)to see an immediate difference; for a fully correct solution, pay attention to and give correct values for the first three arguments ofhtmlspecialchars.