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


  • 相关阅读:
    Windows各种计时器
    C++:数据流和缓冲区
    CImage类的使用介绍!
    PCL:PCL可视化显示点云
    Qt:&OpenCV—Q图像处理基本操作(Code)
    Boost锁~临界区保护和临界资源共享
    关于XML学习
    Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐
    boost多线程使用简例
    一个openMP编程处理图像的示例
  • 原文地址:https://www.cnblogs.com/heiing/p/1716264.html
Copyright © 2011-2022 走看看