Everyday string functions
The functions you will use all the time: length, case, search, cut and clean.
PHP · Everyday string functionsBeginner
$s = ' Hello PHP World ';
$t = trim($s); // 'Hello PHP World'
echo strlen($t); // 15
echo strtoupper($t), strtolower($t);
echo substr($t, 0, 5); // 'Hello'
echo str_replace('PHP', 'Web', $t); // 'Hello Web World'
var_dump(str_contains($t, 'PHP')); // true (PHP 8+)
var_dump(str_starts_with($t, 'Hello')); // true (PHP 8+)
print_r(explode(' ', $t)); // ['Hello','PHP','World']
echo implode('-', ['a', 'b', 'c']); // 'a-b-c'stringtrimsubstr