I have issue in decoding a url received from an iOS app; the url is of th kind:
percorsoWithOption.php?partenza=Via%20Gaspare%20Balbi%202–8&arrivo=Via%20Conca%20d'Oro&language=it_IT&latitude=41.717835&longitude=12.311369&endLatitude=41.679623&endLongitude=12.484474&json=1
and when I try to decode it at the following: Online decoder it is decoded just fine. Yet when I apply:
if (isset($_GET['arrivo'])) $arrivo=$_GET['arrivo'];
if (isset($_GET['partenza'])) $partenza=$_GET['partenza'];
error_log("*inizio**departure=$partenza, arrival=$arrivo, latitude=$latitude, longitude=$longitude");
if (isset($partenza)) $partenza=urldecode($partenza);
if (isset($arrivo)) $arrivo=urldecode($arrivo);
error_log("***departure=$partenza, arrival=$arrivo, latitude=$latitude, longitude=$longitude");
the logs report the values nearly unchanged:
[Tue Dec 01 12:25:22.566615 2015] [:error] [pid 20812] [client 82.61.145.186:37526] *inizio**departure=Via Gaspare Balbi 2\xe2\x80\x938, arrival=Via Conca d'Oro, latitude=41.717835, longitude=12.311369 [Tue Dec 01 12:25:22.569876 2015] [:error] [pid 20812] [client 82.61.145.186:37526] ***departure=Via Gaspare Balbi 2\xe2\x80\x938, arrival=Via Conca d'Oro, latitude=41.717835, longitude=12.311369 basically the 2\xe2\x80\x938 is left untouched.
I ended up using:
-(NSString*)stripNonStandardAndEncode:(NSString*)origin{
NSMutableCharacterSet *charactersToKeep = [NSMutableCharacterSet alphanumericCharacterSet];
[charactersToKeep addCharactersInString:@" ,.'"];
NSCharacterSet *charactersToRemove = [charactersToKeep invertedSet];
NSString *trimmedReplacement = [[ origin componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""];
return [trimmedReplacement stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
And now php handles it seamlessly: url decode may have some issue with character '-'