Phpurl_encode encryption and decryption functions
Last Update:2013-06-26
Source: Internet
Author: User
$ Source = utf8_decode ($ string); // Encode to ISO-8859-1 encoding /**
* Wp Audio Player plug-in music address encryption function
* @ Date 2010/04/07
* Add a code reading comment:
* @ Author: Cola smoke
* @ Url: blog.80aj.com
*/
Function url_encode ($ string)
{
$ Source = utf8_decode ($ string); // Encode the code into ISO-8859-1 encoding
$ Ntexto = "";
$ Codekey = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 _-";
For ($ I = 0; $ I <strlen ($ string); $ I ++ ){
// Echo $ string {$ I}."
"; // Output characters
// Echo ord ($ string {$ I})."
"; // ASCII value of the output character
// Exit ();
$ Ntexto. = substr (0000 ″. base_convert (ord ($ string {$ I}), 10, 2),-8 ); // Convert the ascii value from decimal to binary and add 0000 to the header to take the last 8 digits
}
// Echo $ ntexto;
$ Ntexto. = substr ("00000", 0, 6-strlen ($ ntexto) % 6 ); // Obtain the converted string length. after the remainder of 6, add 0 to ensure that the string length is an integer multiple of 6.
$ String = "";
For ($ I = 0; $ I <strlen ($ ntexto)-1; $ I = $ I + 6 ){
// Echo intval (substr ($ ntexto, $ I, 6), 2)."
"; // Convert the decimal number to a decimal number.
$ String. = $ codekey {intval (substr ($ ntexto, $ I, 6), 2)}; // truncates 6 digits from $ ntexto and returns the character corresponding to the corresponding string
}
Return $ string;
}
/**
* Wp Audio Player plug-in music address decryption function
* @ Author no light in the wilderness
* @ Url http://www.ihacklog.com/
* @ Date 2010/04/05
* Note: it is only used for learning and communication.
*/
Function url_decode ($ source_str)
{
$ Bin_code = ";
$ Str = ";
$ Codekey = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 _-';
$ Source_len = strlen ($ source_str );
For ($ I = 0; $ I <$ source_len; $ I ++ ){
$ Current_strpos = strpos ($ codekey, substr ($ source_str, $ I, 1 ));
$ Sixbit_bin = substr ('000000'. base_convert ($ current_strpos, 10, 2),-6, 6 );
$ Bin_code. = $ sixbit_bin;
}
$ Bin_code_len = strlen ($ bin_code );
For ($ I = 0; $ I <$ bin_code_len; $ I ++ = 8 ){
$ Eight_bit_bin = substr ($ bin_code, $ I, 8 );
$ Ascii_num = base_convert ($ eight_bit_bin, 2, 10 );
$ Str. = chr ($ ascii_num );
}
Return $ str;
}
$ Str = url_encode ("I love you ");
Echo"
". $ Str;