Strings |
| Use |
Syntax |
Example(s) |
| Count the number of characters in a string | Stringlen(subject);) | Stringlen("Hello"); (returns 5) |
| trim whitespace or other characters off the left side of a string | ltrim(string[,characters to trim]) | $hello = "...hello" ltrim(string $hello[,"."]); - returns "Hello World" |
| trim whitespace or other characters off the right side of a string | rtrim(string[,characters to trim]) | $hello = "hello..." rtrim(string $hello[,"."]); - returns "Hello World" |
| compare two strings, return an int depending which is first alphanumerically | strcmp("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 alphanumerically | strncmp("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 characters | Substr(String source,integer Start[,integer length]); | substr("abcdef",2,3); (this returns 'cde' |
| search within a string for another string or character | strpos(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 subject | str_replace("e","3","i am uber leet"(this returns 'i am ub3r l33t\' |
| translate a string, replacing letters with corresponding letters all at once | strtr(string subject, string from, string to); | strtr("good","bad","have a good day" (returns "have a bad day") |