codegurukool.com · Free coding tutorials & online compiler

Home › PHP Tutorial › PHP strings

PHP strings

Measure, search and change text.

PHP has hundreds of string functions. Common ones are strlen, strtoupper, str_replace and strpos. Positions start counting at 0.

Example code

<?php
$s = "Hello, World";
echo strlen($s) . PHP_EOL;
echo strtoupper($s) . PHP_EOL;
echo str_replace("World", "PHP", $s) . PHP_EOL;
echo strpos($s, "World") . PHP_EOL;
?>

Run this code in the online editor

← PHP data typesPHP numbers and math →