zoukankan      html  css  js  c++  java
  • 写了一个PHP的String类

    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;
            
    ifmethod_exists$this, $coder ) )
            {
                
    return $this->$coder();
            }else{
                
    return $this;
            }
        }
        
        
    public function decode( $coder )
        {
            
    $coder = 'decode_' . $coder;
            
    ifmethod_exists$this, $coder ) )
            {
                
    return $this->$coder();
            }else{
                
    return $this;
            }
        }
        
        
    private function encode_md5()
        {
            
    return new Stringmd5$this->_val ) );
        }
        
        
    private function decode_gbk()
        {
            
    return new Stringiconv'GBK', 'UTF-8', $this->_val ) );
        }
        
        
    }


  • 相关阅读:
    java判断字符串是否为数字
    门萨高智商者的集中营
    Android全局变量是用public&nbsp…
    oracle 关闭查询的进程
    oracle 常用参考
    oracle创建临时表
    透明网关设置
    透明网关diy
    又一个下拉菜单导航按钮
    数据库备份或导出时丢失主键的相关知识
  • 原文地址:https://www.cnblogs.com/heiing/p/1716264.html
Copyright © 2011-2022 走看看