String Library

IgnitedCMS ships with a variety of useful string helper utilities

$this->load->library('str');

Function reference

set
Parameters:

string

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello');

(Sets the string object for use later)

Function reference

length
Parameters:

none - returns the length of the current string object as integer

Returns:

int

Return type:

int

$this->load->library('str');
echo $this->str->set('hello')->length()

(Echos '5')

Function reference

print
Parameters:

none

Returns:

Echos string to view

Return type:

Echos string to view

$this->load->library('str');
$this->str->set('hello')->print();

(Echos hello to the view)

The string library supports method chaining

Function reference

join
Parameters:

string - joins to initial string object

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->join(' there')->print();

(Echos 'hello there' to the view)

Function reference

upper
Parameters:

none - convert string object to uppercase

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->upper()->print();

(Echos 'HELLO' to view)

Function reference

lower
Parameters:

none - converts string object to lowercase

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('HELLO')->lower()->print();

(Echos 'hello' to the view)

Function reference

reverse
Parameters:

none - reverses the string object

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->reverse()->print();

(Echos 'olleh' to the view)

Function reference

capitalize
Parameters:

none - Works like Ucfirst (capitalizes the first character of the string object)

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->capitalize()->print();

(Echos 'Hello' to the view)

Function reference

times
Parameters:

integer - number that repeats the string object by

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->times(3)->print();

(Echos 'hellohellohello' to the view)

Function reference

starts_with
Parameters:

string - check if string object starts with var

Returns:

bool - true or false

Return type:

bool

$this->load->library('str');
echo $this->str->set('hello')->starts_with('he');

(Echos true)

Function reference

ends_with
Parameters:

string - test if string object ends with var

Returns:

bool - true or false

Return type:

bool

$this->load->library('str');
echo $this->str->set('hello')->ends_with('he');

(Echos false)

Function reference

pluck
Parameters:

int $start, int $end - a substring position of the string index positions

Returns:

string - substring

Return type:

string

$this->load->library('str');
echo $this->str->set('hello')->pluck(0,2);

(Echos 'hel')

Note: Strings start at array position 0

Function reference

is_alpha
Parameters:

none - return true if all characters are 'abcdefghijklmnopqrstuvwxyz' and uppercase

Returns:

bool - true or false

Return type:

bool

$this->load->library('str');
echo $this->str->set('hello')->is_alpha();

(Echos true)
$this->load->library('str');
echo $this->str->set('hello23')->is_alpha();

(Echos false)
$this->load->library('str');
echo $this->str->set('hello,?')->is_alpha();

(Echos false)

Function reference

is_digit
Parameters:

none - returns true if characters all contain 1234567890

Returns:

bool - true or false

Return type:

bool

$this->load->library('str');
echo $this->str->set('23432')->is_digit();

(Echos true)

Function reference

to_s
Parameters:

none - Attempts to convert string object to type String

Returns:

String

Return type:

String

$this->load->library('str');
$tmp = $this->str->set('hello')->to_s();

(Do something with $tmp later)

Function reference

to_i
Parameters:

none - Attempts to convert string object to integer

Returns:

integer

Return type:

integer

$this->load->library('str');
$tmp = $this->str->set('3')->to_i();

(Do something with $tmp later, allows you to perform math operations)

Function reference

to_f
Parameters:

none - Attempts to convert String to float

Returns:

float

Return type:

float

$this->load->library('str');
$tmp = $this->str->set('12.7')->to_f();

(Do something with $tmp later, apply maths operations)

Function reference

replace
Parameters:

string $needle, string $haystack - search string object and does mass search and replace

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->replace('h','8')->print();

(Echos '8ello')

Function reference

remove
Parameters:

string $var - strings string for occurrences of $var and removes it thus changing the string length

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->remove('ll')->print();

(Echos 'heo' to the view)

Note: This function is case sensitive!

Function reference

trim
Parameters:

none - removes all whitespace, including double whitespace tabs and newlines and trims

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('  hello    there \t\n')->trim()->print();

(Echos 'hello there' to the view)

Function reference

shuffle
Parameters:

none - shuffles the characters in the string object

Returns:

void

Return type:

void

$this->load->library('str');
$this->str->set('hello')->shuffle()->print();

(Example, echos 'loleh' to the view)

Function reference

split
Parameters:

char $delim - splits string object into an array using a single character delimiter

Returns:

array - an array of strings

Return type:

array

$this->load->library('str');
$arr = $this->str->set('hello,there,friend')->split(',');
print_r($arr);

(Echos array of strings to the view)
$this->load->library('str');
$arr = $this->str->set('abcdef')->split('');
print_r($arr);

(Echos array of strings to the view) If no delimiter is found it will split the string by each character