24

How to decode the url in php where url is encoded with encodeURIComponent()?

I have tried the urldecode() but then also..i don't the url which i have encoded...

I have to do this in php..

Nitz
  • 1,690
  • 11
  • 36
  • 56

2 Answers2

33

You should use rawurldecode().
See the Manual

Erenor Paz
  • 3,061
  • 4
  • 37
  • 44
mike
  • 5,047
  • 2
  • 26
  • 32
8

you can use this function:

<?php
$string = 'http%3A%2F%2Fexample.com';
$output = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($string)); 
echo html_entity_decode($output,null,'UTF-8');
?>

output will be : http://example.com

T.Todua
  • 53,146
  • 19
  • 236
  • 237