Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

How to use PHP Magic to create a string builder with append format in PHP.

, 7 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Here is the one i wrote sometime ago/* ---------------------------------------------------------------------------- * Teknober.com - All rights reserved * ---------------------------------------------------------------------------- * File Name : TStringBuilder.php * Section ...
Here is the one i wrote sometime ago
 

/* ----------------------------------------------------------------------------
 * Teknober.com - All rights reserved
 * ----------------------------------------------------------------------------
 * File Name    : TStringBuilder.php
 * Section      : TStringBuilder
 * Dependicies  : none
 * Description  : Implements TStringBuilder class
 * ----------------------------------------------------------------------------
 * Author       : Fatih P
 * E-mail       : v-fpiris@     .com [removed to avoid spam]
 * ----------------------------------------------------------------------------
 * $LastChangedRevision: 38 $
 * --------------------------------------------------------------------------*/
class TStringBuilder {
    private $str = null;
 
    /**
     * Initializes a new instance
     */
    public function __construct()
    {
        $this->str = array();
    }
 
    /**
     * Adds new string
     * @param string $str
     */
    public function add($str)
    {
        $this->str[] = $str;
    }
 
    /**
     * Clears the string
     */
    public function clear() {
        $this->str = array();
    }
 
    /**
     * Gets internal array
     */
    public function get() {
        $this->str;
    }
 
    /**
     * Dumps string
     * @param string $seperator
     * @return string
     */
    public function dump($seperator = "") {
        $retVal = "";
        foreach($this->str as $k) {
            $retVal .= $k . $seperator;
        }
 
        return substr($retVal, 0, strlen($retVal) - strlen($seperator));
    }
 
    /**
     * Get number of enteries added
     * @return int
     */
    public function count() {
        return count($this->str);
    }
 
    /**
     * Get string length
     * @return int
     */
    public function length() {
        $retVal = 0;
        foreach($this->str as $k) {
            $retVal += strlen($k);
        }
 
        return retVal;
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Fatih P.
Software Developer (Senior) Solution Developer
Hungary Hungary
Consultant and Solution Developer with experience in following areas:
 
* Web Application Development using .NET or/and PHP
* Application Development using .NET
* Relational Database Design and Development or NoSQL Solutions
* Front-End Development, Design and Accessibility
* JavaScript (Core, jQuery and Prototype) and JSON
* HTML (Strict and Transitional), HTML5
* CSS (Cross browser compliant)
* Development of RIAs using Silverlight with down-level implementation.
* Optimization of Websites
* W3 Standards
* SEO Compliance
* Maps (Google Maps API and OpenStreetMap)
* Managing and Administering Web, DNS, Mail, SVN and Database Servers
* Research and Development
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 7 Feb 2011
Article Copyright 2011 by Fatih P.
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid