PHP has many built-in functions for manipulating strings. Here are some examples of common string functions:
- strlen() – Returns the length of a string.
- strtolower() – Converts a string to lowercase.
- strtoupper() – Converts a string to uppercase.
- substr() – Extracts a portion of a string.
- str_replace() – Replaces all occurrences of a search string with a replacement string.
- trim() – Removes whitespace from the beginning and end of a string.
- strpos() – Finds the position of the first occurrence of a substring in a string.
- str_split() – Splits a string into an array.
Here are some examples of how you can use these functions:
$string = 'Hello World';
echo strlen($string); // Outputs 11
echo strtolower($string); // Outputs hello world
echo strtoupper($string); // Outputs HELLO WORLD
echo substr($string, 6); // Outputs World
echo str_replace('World', 'Earth', $string); // Outputs Hello Earth
echo trim(' Hello World '); // Outputs Hello World
echo strpos($string, 'World'); // Outputs 6
print_r(str_split($string, 3)); // Outputs Array ( [0] => Hel [1] => lo [2] => Wor [3] => ld )