MString

MString is loaded by default.

Public Methods



random($length:int):String


Returns a random string of character the length at which is requested.
Characters avalible are 0-9 a-z and A-Z for a total of 62 characters.

MString::random(8); 
string(8) "StxphhO5"

to_boolean($string:String):Boolean


Converts a string of "true" into a boolean of TRUE and a string of "false" into a boolean of FALSE. This is sometimes needed when going between JavaScript and PHP with AJAX.

MString::to_boolean("true"); 
bool(true)
MString::to_boolean("false"); 
bool(false)
MString::to_boolean("1"); 
bool(true)
MString::to_boolean("0"); 
bool(false)

sub_before($string:String, $character:String):String


Given a string and a character or set of characters this function will return a substring before the first occurance of the set. This function was added when MogulPHP was not required to run on PHP 5.3 and thus did not have access to the optional third parameter of the strstr() command in PHP 5.3.

MString::sub_before("The quick brown fox jumped over the lazy dog", "jumped"); 
string(20) "The quick brown fox "
MString::sub_before("The quick brown fox jumped over the lazy dog", "b"); 
string(10) "The quick "

url_title($string:String, $seperator:String):String


Converts a given string into a character seperated URL title safe string. This function also lower cases the string. The optional second parameter allows you to pass in your own character, otherwise a dash (-) is used.

MString::url_title("The quick brown fox jumped over the lazy dog"); 
string(44) "the-quick-brown-fox-jumped-over-the-lazy-dog"
MString::url_title("The quick brown fox jumped over the lazy dog", "+"); 
string(44) "the+quick+brown+fox+jumped+over+the+lazy+dog"

newline_remove($string:String):String


This function returns a string without the new line ("\n") character.

MString::newline_remove("A
string 
with
new
lines."); 
string(25) "A string with new lines."