-1

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.

Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75

3 Answers3

0

It's not "nearly unchanged", it's URL-decoding just fine. The only issue is that the en dash is showing up as "\xe2\x80\x93" in your log.

  1. It's unclear whether this is an issue of how values are logged or viewed, or whether the value is actually "\xe2\x80\x93". To test this, use bin2hex() on your string and see whether it shows up as e28093 (just the – character) or 5c78... (literally "\x...").
  2. That en dash should be sent URL-encoded as %E2%80%93 in the URL, not as the raw character. Fix this on the client.
deceze
  • 510,633
  • 85
  • 743
  • 889
0

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 '-'

Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75
-1

You can use rawurldecode function.

Suman Biswas
  • 853
  • 10
  • 19