Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 929
Nitz Avatar asked May 03 '10 12:05

Nitz


People also ask

How decode URL in PHP?

PHP | urldecode() Function The urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.

How encode URL in PHP?

PHP | urlencode() Function. The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

Should I use encodeURI or encodeURIComponent?

encodeURIComponent should be used to encode a URI Component - a string that is supposed to be part of a URL. encodeURI should be used to encode a URI or an existing URL.


2 Answers

You should use rawurldecode().
See the Manual

like image 145
mike Avatar answered Sep 24 '22 08:09

mike


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

like image 29
T.Todua Avatar answered Sep 26 '22 08:09

T.Todua