一个PHP的String类代码
2015-01-24信息快讯网
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 ) );
}
}
PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
phpmyadmin安装时提示:Warning: require_once(./libraries/common.inc.php)错误解决办法
php中使用Curl、socket、file_get_contents三种方法POST提交数据
PHP中static关键字原理的学习研究分析
ajax 的post方法实例(带循环)
PHP 数据结构 算法 三元组 Triplet
Can't create/write to file 'C:\WINDOWS\TEMP\...MYSQL报错解决方法
php设计模式 Strategy(策略模式)
php设计模式 State (状态模式)
php设计模式 Bridge (桥接模式)
Warning: session_destroy() : Trying to destroy uninitialized sessionq错误
php中session_unset与session_destroy的区别分析
php错误提示failed to open stream: HTTP request failed!的完美解决方法
php 截取字符串并以零补齐str_pad() 函数
PHP中simplexml_load_string函数使用说明
php iconv() : Detected an illegal character in input string
PHP中的string类型使用说明
PHP STRING 陷阱原理说明
php快速url重写 更新版[需php 5.30以上]
使用PHP提取视频网站页面中的FLASH地址的代码
php读取javascript设置的cookies的代码
ajax+php打造进度条代码[readyState各状态说明]
php echo()和print()、require()和include()函数区别说明
mysql From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT日期函数
ajax+php打造进度条 readyState各状态
PHP clearstatcache()函数详解
PHP strtok()函数的优点分析
php str_pad() 将字符串填充成指定长度的字符串
php中理解print EOT分界符和echo EOT的用法区别小结
php 正确解码javascript中通过escape编码后的字符
php addslashes和mysql_real_escape_string
PHP strtotime函数详解
Php 构造函数construct的前下划线是双的_
php面向对象全攻略 (十一)__toString()用法 克隆对象 __call处理调用错误