What are some common functions or methods in PHP for string concatenation and manipulation?
When working with strings in PHP, it is common to need to concatenate or manipulate them in various ways. Some common functions and methods for string concatenation and manipulation in PHP include the concatenation operator (.), the `strlen()` function to get the length of a string, the `substr()` function to extract a substring, the `str_replace()` function to replace occurrences of a substring, and the `strtolower()` and `strtoupper()` functions to convert a string to lowercase or uppercase, respectively.
// String concatenation
$string1 = "Hello";
$string2 = "World";
$concatenatedString = $string1 . " " . $string2;
echo $concatenatedString; // Output: Hello World
// Get the length of a string
$length = strlen($concatenatedString);
echo $length; // Output: 11
// Extract a substring
$substring = substr($concatenatedString, 6);
echo $substring; // Output: World
// Replace occurrences of a substring
$newString = str_replace("World", "PHP", $concatenatedString);
echo $newString; // Output: Hello PHP
// Convert a string to lowercase or uppercase
$lowercaseString = strtolower($concatenatedString);
$uppercaseString = strtoupper($concatenatedString);
echo $lowercaseString; // Output: hello world
echo $uppercaseString; // Output: HELLO WORLD