一個(gè)PHP的String類(lèi)代碼
更新時(shí)間:2010年04月20日 20:04:28 作者:
PHP String 類(lèi),暫時(shí)只有encode,decode方法
使用方法:
$s ='中國(guó)';
$os = new String( $s );
echo $os->decode('gbk') ,'';
echo $os->decode('gbk')->encode('md5'),'';
代碼
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 ='decode_' . $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 ) );
}
}
復(fù)制代碼 代碼如下:
$s ='中國(guó)';
$os = new String( $s );
echo $os->decode('gbk') ,'';
echo $os->decode('gbk')->encode('md5'),'';
代碼
復(fù)制代碼 代碼如下:
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 ='decode_' . $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 ) );
}
}
相關(guān)文章
php操作JSON格式數(shù)據(jù)的實(shí)現(xiàn)代碼
php操作JSON格式數(shù)據(jù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-12-12php使用mysqli向數(shù)據(jù)庫(kù)添加數(shù)據(jù)的方法
這篇文章主要介紹了php使用mysqli向數(shù)據(jù)庫(kù)添加數(shù)據(jù)的方法,實(shí)例分析了php使用mysqli進(jìn)行數(shù)據(jù)庫(kù)操作的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03PHP MemCached 高級(jí)緩存應(yīng)用代碼
PHP MemCached 高級(jí)緩存應(yīng)用,使用MemCached的學(xué)習(xí)的朋友可以參考下。2010-08-08php實(shí)現(xiàn)的debug log日志操作類(lèi)實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)的debug log日志操作類(lèi),結(jié)合實(shí)例形式分析了php針對(duì)日志的相關(guān)操作技巧,包括php數(shù)組、字符串及文件的寫(xiě)操作等用法,需要的朋友可以參考下2016-07-07PHP數(shù)組游標(biāo)實(shí)現(xiàn)對(duì)數(shù)組的各種操作詳解
這篇文章主要介紹了PHP數(shù)組游標(biāo)實(shí)現(xiàn)對(duì)數(shù)組的各種操作,結(jié)合實(shí)例形式較為詳細(xì)的分析了PHP數(shù)組操作中current與next方法控制數(shù)組游標(biāo)移動(dòng)實(shí)現(xiàn)數(shù)組遍歷的技巧,需要的朋友可以參考下2016-01-01一個(gè)嚴(yán)格的PHP Session會(huì)話(huà)超時(shí)時(shí)間設(shè)置方法
這篇文章主要介紹了一個(gè)嚴(yán)格的PHP Session會(huì)話(huà)超時(shí)時(shí)間設(shè)置方法,著重點(diǎn)在于結(jié)合兩種方法保證超時(shí)時(shí)間到,會(huì)話(huà)失效,需要的朋友可以參考下2014-06-06