PHP Strings
PHP has many string functions. Use double quotes to insert variables; single quotes keep text exactly as written.
ExamplePHP
<?php
$s = "Hello, PHP";
echo strlen($s) . "\n";
echo strtoupper($s) . "\n";
echo substr($s, 7) . "\n";
echo strpos($s, "PHP") . "\n";
echo str_replace("PHP", "World", $s) . "\n";
echo str_pad("7", 3, "0", STR_PAD_LEFT) . "\n";
echo ucwords("hello big world") . "\n";
print_r(explode(",", "a,b,c"));
echo implode("-", ["x", "y", "z"]) . "\n";
$n = 5;
echo 'single: $n' . "\n";
echo "double: $n\n";
echo sprintf("%05.1f", 3.14159) . "\n";Output
10
HELLO, PHP
PHP
7
Hello, World
007
Hello Big World
Array
(
[0] => a
[1] => b
[2] => c
)
x-y-z
single: $n
double: 5
003.1Quick check
Which quotes insert variables into a string?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.