Phpurl_encode encryption and decryption functions

Source: Internet
Author: User
Tags decimal to binary
$ 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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.