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


  • 相关阅读:
    理解 RESTful:理论与最佳实践
    Shiro 性能优化:解决 Session 频繁读写问题
    单点登录的三种实现方式
    理解 Spring(二):AOP 的概念与实现原理
    理解 Spring(一):Spring 与 IoC
    MFC查内存泄漏方法
    024 --- 第28章 访问者模式
    023 --- 第27章 解释器模式
    022 --- 第26章 享元模式
    021 --- 第25章 中介者模式
  • 原文地址:https://www.cnblogs.com/heiing/p/1716264.html
Copyright © 2011-2022 走看看