urlencode and urldecode in php
Posted by Raj
urlencode :-Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.
Syntax:
string urlencode ( string $str );
Example:
<?php
$url="Rajesh SharmaTutorials";
$encodeUrl=urlencode($url);
echo '<a href="test.php?sample=$encodeUrl">';
?>
Output: <a href="test.php?sample=Rajesh+Sharma+Tutorials">
urldecode :- Returns the decoded string.(Returns the original string of the input URL).
<?php
$sample=$_GET["sample"];
echo $sample=urldecode($sample);
?>
Output:Rajesh SharmaTutorials
Syntax:
string urlencode ( string $str );
Example:
<?php
$url="Rajesh SharmaTutorials";
$encodeUrl=urlencode($url);
echo '<a href="test.php?sample=$encodeUrl">';
?>
Output: <a href="test.php?sample=Rajesh+Sharma+Tutorials">
urldecode :- Returns the decoded string.(Returns the original string of the input URL).
<?php
$sample=$_GET["sample"];
echo $sample=urldecode($sample);
?>
Output:Rajesh SharmaTutorials
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
PHP,
PHP interview questions and answers,
php urlencode,
url decode,
url encode,
url encoder,
url encoding,
URLDecode,
urlencode
.You can leave a response, or trackback from your own site.