How to encode or decode variables in PHP
I want to encode a variable in PHP5, do some operation and then decode it. For this I want to know which function is appropriate for this kind of operations. In short, is there any function that will encode and decode a variable? How any one provide me any solution with some details?
Re: How to encode or decode variables in PHP
You can use MySQL's encode and decode functions in your PHP code as follows:
PHP Code:
<?php
$encVariable = mysql_query("SELECT ENCODE('variable_name','')");
$encString = mysql_fetch_array($encVariable);
$val_enc = $encodedString[0];
echo $val_enc."<br>\n";
$decVariable = mysql_query("SELECT DECODE('".$val_enc."','')");
$decString = mysql_fetch_array($decVariable);
$val_dec = $decString[0];
echo $val_dec;
?>
Re: How to encode or decode variables in PHP
Use urlencode () and urldecode (). Here is how to use them.
urlencode
This function is convenient when encoding a string to be used in a query part of a URL.
PHP Code:
string urlencode (string $str)
where,
str = The string to be encoded.
urldecode
Decodes any encoding in the given string.
PHP Code:
string urldecode (string $str)
where,
str = The string to be decoded.