Manipulating PHP strings
- Strip out white spaces from either side of the string: trim(string);
- Make sure that the first character is uppercase (eg. People's name): ucfirst(string);
- Search for the first occurence of a string: strpos(string, pattern to match);
- Search for the last occurence of a string: strrpos(string, pattern to match);
- Search and replace a string: str_replace(string to search for, string to replace with, string/message);
- Compare two strings. If the strings do not match then a non-zero value will be returned. If both strings match then a zero is returned: strcmp(string1, string2);
- Split a string into an array. To be able to split a string into an array, there must be a separator. the space ' ' is the most common but for eg. files, the separator could be a tab or a colon: explode (string separator, string); explode(":", $passwd_line);
- Convert new lines to HTML <br> tag: nl2br(string);