Home >Backend Development >PHP Tutorial >PHP simulates asp.net's StringBuilder class implementation method, _PHP tutorial

PHP simulates asp.net's StringBuilder class implementation method, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:44:55824browse

PHP simulates the StringBuilder class implementation method of asp.net,

The example in this article describes the PHP simulation asp.net StringBuilder class implementation method. Share it with everyone for your reference. The details are as follows:

In the asp.net development environment, there is a StringBuilder class that is commonly used. This class can be used to implement very convenient text manipulation. But in PHP, there is no such class. However, we can use it automatically Define a class to simulate this method.

/******************************************** 
 * 
 * 函数名:StringBuilder 
 * 作 用:构造PHP下的StringBuilder类 
 * 
 ********************************************/
class StringBuilder 
{ 
  const LINE="<br/>"; 
  protected $list= array(''); 
  public function __construct( $str=NULL) 
  { 
    array_push($this->list,$str); 
  } 
  public function Append($str) 
  { 
    array_push($this->list,$str); 
    return $this; 
  } 
  public function AppendLine($str) 
  { 
    array_push($this->list,$str.self::LINE); 
    return $this; 
  } 
  public function AppendFormat( $str,mixed $args) 
  { 
    array_push($this->list, sprintf($str,$args)); 
    return $this; 
  } 
  public function ToString() 
  { 
    return implode("",$this->list); 
  } 
  public function __destruct() 
  { 
    unset($this->list); 
  } 
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1044855.htmlTechArticlePHP simulates the StringBuilder class implementation of asp.net. The example of this article describes the PHP simulation of asp.net's StringBuilder class implementation. method. Share it with everyone for your reference. The details are as follows: In asp.ne...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn