PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

一个PHP的String类代码_PHP教程

原创
2016-07-21 15:38:36 545浏览

使用方法:

复制代码 代码如下:

$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 ) );
}
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321738.htmlTechArticle使用方法: 复制代码 代码如下: $s ='中国'; $os = new String( $s ); echo $os-decode('gbk') ,''; echo $os-decode('gbk')-encode('md5'),''; 代码 复制代码 代码如下...
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。