一個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 ) );
}
}
復(fù)制代碼 代碼如下:
$s ='中國';
$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 Class&Object -- PHP 自排序二叉樹的深入解析
本篇文章是對PHP中的自排序二叉樹進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PHP Primary script unknown 解決方法總結(jié)
在本篇文章里小編給大家整理的是關(guān)于PHP Primary script unknown 終極解決方法以及相關(guān)知識點(diǎn),有需要的朋友們參考學(xué)習(xí)下。2019-08-08
PHP基于MySQLI函數(shù)封裝的數(shù)據(jù)庫連接工具類【定義與用法】
這篇文章主要介紹了PHP基于MySQLI函數(shù)封裝的數(shù)據(jù)庫連接工具類,結(jié)合實(shí)例形式分析了php封裝mysqli函數(shù)實(shí)現(xiàn)的數(shù)據(jù)庫操作類定義及連接、增刪改查數(shù)據(jù)庫等基本操作用法,需要的朋友可以參考下2017-08-08

