A php String code. Usage: Copy the code as follows: $ s China; $ osnewString ($ s); echo $ OS-decode (gbk),; echo $ OS-decode (gbk) -encode (md5); the code copy code is as follows:
Usage:
The code is as follows:
$ S = 'China ';
$ OS = new String ($ s );
Echo $ OS-> decode ('gbk '),'';
Echo $ OS-> decode ('gbk')-> encode ('md5 '),'';
Code
The code is as follows:
Class String extends stdClass
{
Private $ _ val = '';
Public function _ construct ($ str = '')
{
$ This-> _ val = $ str;
}
Public function _ toString ()
{
Return $ this-> _ val;
}
Public function encode ($ coder)
{
$ Coder = 'encode _ '. $ coder;
If (method_exists ($ this, $ coder ))
{
Return $ this-> $ coder ();
} Else {
Return $ this;
}
}
Public function decode ($ coder)
{
$ Coder = 'code _ '. $ coder;
If (method_exists ($ this, $ coder ))
{
Return $ this-> $ coder ();
} Else {
Return $ this;
}
}
Private function encode_md5 ()
{
Return new String (md5 ($ this-> _ val ));
}
Private function decode_gbk ()
{
Return new String (iconv ('gbk', 'utf-8', $ this-> _ val ));
}
}
The response code is as follows: $ s = 'China'; $ OS = new String ($ s); echo $ OS-decode ('gbk '),''; echo $ OS-decode ('gbk')-encode ('md5'), ''; the code is as follows...