PHP Fundamentals

Learn PHP programming from scratch, including variables, functions, arrays, and object-oriented programming.

beginner Backend Development 6 hours

Chapter 9: Working with Strings

Chapter 9 of 15

Chapter 9: Working with Strings

9.1 String Operations

$str1 = "Hello";
$str2 = "World";
$combined = $str1 . " " . $str2;  // Concatenation

9.2 String Functions

strlen($string);                    // Get length
strtolower($string);                // Convert to lowercase
strtoupper($string);                // Convert to uppercase
substr($string, 0, 5);             // Extract substring
str_replace("old", "new", $string); // Replace text

9.3 String Formatting

sprintf("Hello, %s! You are %d years old.", $name, $age);
$formatted = number_format(1234.56, 2);