一個PHP的String類代碼
更新時間:2010年04月20日 20:04:28 作者:
PHP String 類,暫時只有encode,decode方法
使用方法:
$s ='中國';
$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 ) );
}
}
復制代碼 代碼如下:
$s ='中國';
$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 ) );
}
}
相關文章
php操作JSON格式數(shù)據(jù)的實現(xiàn)代碼
php操作JSON格式數(shù)據(jù)的實現(xiàn)代碼,需要的朋友可以參考下。2011-12-12php使用mysqli向數(shù)據(jù)庫添加數(shù)據(jù)的方法
這篇文章主要介紹了php使用mysqli向數(shù)據(jù)庫添加數(shù)據(jù)的方法,實例分析了php使用mysqli進行數(shù)據(jù)庫操作的技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03PHP數(shù)組游標實現(xiàn)對數(shù)組的各種操作詳解
這篇文章主要介紹了PHP數(shù)組游標實現(xiàn)對數(shù)組的各種操作,結合實例形式較為詳細的分析了PHP數(shù)組操作中current與next方法控制數(shù)組游標移動實現(xiàn)數(shù)組遍歷的技巧,需要的朋友可以參考下2016-01-01