一个PHP的String类代码
程序员文章站
2022-07-11 08:33:15
使用方法: 复制代码 代码如下: $s ='中国'; $os = new string( $s ); echo $os->decode('gbk') ,''; ech...
使用方法:
$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 ) );
}
}
上一篇: 【VS2019】Web项目发布时提示无法连接FTP服务器
下一篇: php在字符串中查找另一个字符串