Introduction
String functions help us work with text easily. They save time and avoid mistakes when changing or checking words.
String functions help us work with text easily. They save time and avoid mistakes when changing or checking words.
function_name(string $text, ...$params): mixed
strlen("hello")
strtoupper("hello")
strpos("hello world", "world")
substr("hello world", 0, 5)
This program shows how to use some common string functions in PHP. It prints the original text, its length, the uppercase version, the position of a word, and a part of the text.
<?php $text = "Hello World!"; $length = strlen($text); $upper = strtoupper($text); $pos = strpos($text, "World"); $part = substr($text, 6, 5); echo "Original text: $text\n"; echo "Length: $length\n"; echo "Uppercase: $upper\n"; echo "Position of 'World': $pos\n"; echo "Substring: $part\n"; ?>
Remember that string positions start at 0 in PHP.
Functions like strpos return false if the word is not found, so check carefully.
String functions make working with text easier and faster.
They help find, change, cut, and join text safely.
Using them avoids errors and saves time in programming.
$text = "Hello World!";
$result = substr($text, 6, 5);
echo $result;
$text = "hello";
$upper = strtoupper $text;
echo $upper;
Pass the test and this pattern moves unknown