Creating Strings:
') or double quotes (").$string1 = 'Single quoted string';
$string2 = "Double quoted string";
Concatenation:
.) operator or the compound assignment operator (.= ).$concatenated = $string1 . ' ' . $string2;
$concatenated .= ' Appended text';
String Length:
strlen() function to get the length of a string.$length = strlen($string1);
Substring:
substr() function.$substring = substr($string1, 0, 6); // Extracts first 6 characters
String Replacement:
str_replace() function.$newString = str_replace('old', 'new', $string1);
String Case:
strtolower(), strtoupper(), ucfirst(), ucwords() functions.$lowercase = strtolower($string1);
$uppercase = strtoupper($string1);
$capitalizeFirst = ucfirst($string1);
$capitalizeWords = ucwords($string1);
String Trimming:
trim(), ltrim(), rtrim() functions.$trimmed = trim($string1);
String Splitting:
explode() function based on a delimiter.$parts = explode(' ', $string1); // Split by space
String Joining:
implode() or join() function.$joined = implode(', ', $parts); // Join with comma and space
String Comparison:
strcmp(), strcasecmp(), or equality operators (==, ===).$result = strcmp($string1, $string2);
if ($string1 === $string2) {
// Strings are equal
}
Regular Expressions:
preg_match(), preg_replace(), etc.