| Home | Control Structures | Arrays | Strings | Regular Expressions | Misc |

 

Strings
Use Syntax Example(s)
Count the number of characters in a stringStringlen(subject);)Stringlen("Hello"); (returns 5)
trim whitespace or other characters off the left side of a stringltrim(string[,characters to trim])$hello = "...hello" ltrim(string $hello[,"."]); - returns "Hello World"
trim whitespace or other characters off the right side of a stringrtrim(string[,characters to trim])$hello = "hello..." rtrim(string $hello[,"."]); - returns "Hello World"
compare two strings, return an int depending which is first alphanumericallystrcmp("String 1","String 2");strcmp("Aardvark","Zebra"); (this would return a number <0 because String1 is less)
compare a certain number of characters from two strings, return an int depending which is first alphanumericallystrncmp("String 1","String 2","number");strcmp("Monkey","Mongoose","3");(this returns 0 because the first 3 letters are the same)
return a part of a string starting an amount of characters in and reading a certain amount of charactersSubstr(String source,integer Start[,integer length]);substr("abcdef",2,3); (this returns 'cde'
search within a string for another string or characterstrpos(string haystack, string needle[,integer start]strpos("hello world", "world",3(this starts searching 3 characters from the start, and returns 6 because 'world' is 6 characters from the beginning)
replace all instances of a given string or character with another, in a given string.str_replace(mixed search, mixed replace, mixed subjectstr_replace("e","3","i am uber leet"(this returns 'i am ub3r l33t\'
translate a string, replacing letters with corresponding letters all at oncestrtr(string subject, string from, string to);strtr("good","bad","have a good day" (returns "have a bad day")