加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

一个PHP的String类代码

发布时间:2020-12-13 05:42:10 所属栏目:PHP教程 来源:网络整理
导读:使用方法: 代码如下: $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 ='' ) { $th

使用方法:


代码如下:
$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 ) );
}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读