PHPString class. Currently, only the encode and decode methods are supported.
PHP String class. Currently, only the encode and decode methods are supported.
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 ));
}
}