String
[ class tree: String ] [ index: String ] [ all elements ]

Class: String

Source Location: /String.class.php

Class Overview


Generic class for PHP to handle strings on a way inspired by C++.


Author(s):

  • Benjamin Hofmann

Version:

  • 1.1.0

Copyright:

  • Benjamin Hofmann

Variables

Constants

Methods


Child classes:

JavascriptString
Extension to the String class to define similar methods like in javascript.

Class Details

[line 32]
Generic class for PHP to handle strings on a way inspired by C++.

Generic class for PHP to handle strings on a way inspired by C++.




Tags:

author:  Benjamin Hofmann
version:  1.1.0
copyright:  Benjamin Hofmann
link:  http://www.ajaveeb.de/entwicklungen/php-klasse-fuer-strings-306/
since:  2009-01-31


[ Top ]


Class Variables

$string =  null

[line 35]



Tags:

access:  protected

Type:   mixed


[ Top ]



Class Methods


static method callFunction [line 126]

static string callFunction( mixed $string, string $function, [ $params = array()])

Calls the given string function.

Calls the given string function. If a multibyte version exists this is used. Because a static method can not use $this->string this must be given through a parameter. The function name is required. If parameters are needed these are passed in an array except the first parameter, because this is always the string itself and is not needed. Usage:

  1. $this->string self::callFunction($this->string'substr'array(210));




Tags:

access:  protected


Parameters:

mixed   $string  
string   $function  
array   $params  

[ Top ]

method add [line 184]

String add( mixed $string, [mixed $delimiter = ''], [int $position = self::STRING_AFTER])

Adds the given string to the existing string.

Adds the given string to the existing string. The given string can either be a normal string or a String object. This applies also to the delimiter. To delimit the given string from the existing one you can use another string or one of the String::CONTROL_CHAR_ constants. You can also combine some of these constants, e.g. String::CONTROL_CHAR_CARRIAGE_RETURN . String::CONTROL_CHAR_LINEFEED To define the position of the new string use the class constants String::STRING_BEFORE or String::STRING_AFTER. The default position is after the existing string. Usage:

  1. $string new String('This is the new string.');
  2.  $string->add(new String('This is a new string object.')' That is the delimiter. 'String::STRING_BEFORE);
  3.  $string->add('This string is added at the end of the existing one.'String::CONTROL_CHAR_LINEFEEDString::STRING_AFTER);




Tags:

access:  public


Parameters:

mixed   $string  
mixed   $delimiter  
int   $position  

[ Top ]

method addMore [line 228]

String addMore( $stringArray, [mixed $delimiter = ''], [int $position = self::STRING_AFTER])

With this you can add an array of strings.

With this you can add an array of strings. The given strings can either be a normal string or a String object. This applies also to the delimiter. To delimit the given strings from the existing one you can use another string or one of the String::CONTROL_CHAR_ constants. You can also combine some of these constants, e.g. String::CONTROL_CHAR_CARRIAGE_RETURN . String::CONTROL_CHAR_LINEFEED To define the position of the new strings use the class constants String::STRING_BEFORE or String::STRING_AFTER. The default position is after the existing string. Usage:

  1. $string new String('This is the new string.');
  2.  $newString new String('This is a new string object.');
  3.  $string->addMore(array($newString'This string will be positioned even before the first string of this array.')String::CONTROL_CHAR_LINEFEEDString::STRING_BEFORE);




Tags:

access:  public


Parameters:

array   $stringArray  
mixed   $delimiter  
int   $position  

[ Top ]

constructor __construct [line 56]

String __construct( [mixed $string = ''])

With this method a new string is created.

With this method a new string is created. This is a wrapper for $this->set(). Usage:

  1. $string new String('This is the new string.');




Tags:

access:  public


Parameters:

mixed   $string  

[ Top ]

method copy [line 320]

String copy( )

Creates a new String object from the existing one.

Creates a new String object from the existing one. This could be useful, if you want to add different new string to the same base. Usage:

  1. $string new String('This is the new string.');
  2.  $copiedString $string->copy();
  3.  $copiedString->show();




Tags:

access:  public


[ Top ]

method edit [line 157]

String edit( string $function, [ $params = array()])

Calls the given string function.

Calls the given string function. If a multibyte version exists this is used. The function name is required. If parameters are needed these are passed in an array except the first parameter, because this is always the string itself and is not needed. Usage:

  1. $string new String('This is the new string.');
  2.  $string->edit('trim');
  3.  $string->edit('substr'array(210));




Tags:

access:  public


Parameters:

string   $function  
array   $params  

[ Top ]

method get [line 89]

string get( )

Returns the string.

Returns the string. Usage:

  1. $string new String('This is the new string.');
  2.  $string->get();




Tags:

access:  public


[ Top ]

method insert [line 252]

String insert( mixed $string, int $offset)

To insert a string into an existing one use this method.

To insert a string into an existing one use this method. The given string can either be a normal string or a string object. The offset has to be an integer. Usage:

  1. $string new String('This is the new string.');
  2.  $string->insert('Insertion'5);




Tags:

access:  public


Parameters:

mixed   $string  
int   $offset  

[ Top ]

method insertMore [line 286]

String insertMore( $stringArray, int $offset)

To insert an array of string into an existing one use this method.

To insert an array of string into an existing one use this method. The given strings can either be a normal string or string objects. The offset has to be an integer. Usage:

  1. $string new String('This is the new string.');
  2.  $newString new String('This is a new string object.');
  3.  $string->insertMore(array('Insertion'$newString)5);




Tags:

access:  public


Parameters:

array   $stringArray  
int   $offset  

[ Top ]

method reset [line 334]

String reset( )

Resets the existent string.

Resets the existent string. A new string can then be set. Usage:

  1. $string new String('This is the new string.');
  2.  $string $string->reset();




Tags:

access:  public


[ Top ]

method set [line 71]

String set( mixed $string)

Sets a string for further editing or return of the string.

Sets a string for further editing or return of the string. Usage:

  1. $string new String();
  2.  $string->set('This is the new string.');




Tags:

access:  public


Parameters:

mixed   $string  

[ Top ]

method show [line 103]

String show( )

Shows the string.

Shows the string. Usage:

  1. $string new String('This is the new string.');
  2.  $string->show();




Tags:

access:  public


[ Top ]

method __call [line 356]

String __call( string $name, [ $params = array()])

This magic method will be used if the used method does not actually exist.

This magic method will be used if the used method does not actually exist. The big clue with this method is that it delegates the used method name and its parameters to $this->edit(), which then tries to execute the string function. So it is possible to directly use some string functions, e.g. substr(). The example below shows how this could be used. Usage:

  1. $string new String('This is the new string.');
  2.  $string->substr(216)->show();




Tags:

access:  public


Parameters:

string   $name  
array   $params  

[ Top ]

method __toString [line 375]

string __toString( )

This magic method will be used if a script tries to cast this object into a normal string.

This magic method will be used if a script tries to cast this object into a normal string. Normally a warning of the type E_RECOVERABLE_ERROR would be thrown. But with this method the string will be returned. Usage:

  1. $string new String('This is the new string.');
  2.  echo $string;




Tags:

access:  public


[ Top ]


Class Constants

CONTROL_CHAR_CARRIAGE_RETURN =  "\r"

[line 43]


[ Top ]

CONTROL_CHAR_FORM_FEED =  "\f"

[line 46]


[ Top ]

CONTROL_CHAR_HORIZONTAL_TAB =  "\t"

[line 44]


[ Top ]

CONTROL_CHAR_LINEFEED =  "\n"

[line 42]


[ Top ]

CONTROL_CHAR_VERTICAL_TAB =  "\v"

[line 45]


[ Top ]

STRING_AFTER =  2

[line 39]


[ Top ]

STRING_BEFORE =  1

[line 38]


[ Top ]



Documentation generated on Sun, 05 Jul 2009 15:24:32 +0200 by phpDocumentor 1.4.1