Strings
Join strings with the dot operator. Useful functions: strlen, strtoupper, strtolower, str_replace, substr, strpos, trim, explode, implode, str_contains and ucfirst. Heredoc syntax holds long multi-line text.
Example
$s = "Hello, PHP";
echo strlen($s), "\n";
echo strtoupper($s), "\n";
echo substr($s, 7), "\n";
echo str_replace("PHP", "World", $s), "\n";
echo strpos($s, "PHP"), "\n";
echo "Ada" . " " . "Lovelace", "\n";
print_r(explode(",", "a,b,c"));
echo implode("-", ["x", "y", "z"]), "\n";
var_dump(str_contains($s, "PHP"));Result
10
HELLO, PHP
PHP
Hello, World
7
Ada Lovelace
Array
(
[0] => a
[1] => b
[2] => c
)
x-y-z
bool(true)Exercise
Join two strings.
echo "a" "b";
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.