🔹 1. What is String Manipulation?
Meaning:
String manipulation refers to performing operations on strings such as:
Finding length
Changing case
Extracting parts
Replacing text
Comparing strings
� 2. Important String Functions in PHP
� (1) strlen() – Length of String
Function: Counts number of characters.
$str = "Hello";
echo strlen($str);
Output: 5
� (2) str_word_count() – Count Words
$str = "Hello World PHP";
echo str_word_count($str);
Output: 3
� (3) strrev() – Reverse String
$str = "Hello";
echo strrev($str);
Output: olleH
� (4) strpos() – Find Position
Finds position of a word in string.
$str = "Hello World";
echo strpos($str, "World");
Output: 6
� (5) str_replace() – Replace Text
$str = "Hello World";
echo str_replace("World", "PHP", $str);
Output: Hello PHP
� (6) strtolower() – Lowercase
echo strtolower("HELLO");
Output: hello
� (7) strtoupper() – Uppercase
echo strtoupper("hello");
Output: HELLO
� (8) ucfirst() – First Letter Capital
echo ucfirst("hello world");
Output: Hello world
� (9) ucwords() – First Letter of Each Word
echo ucwords("hello world php");
Output: Hello World Php
� (10) trim() – Remove Spaces
$str = " Hello ";
echo trim($str);
Output: Hello
� (11) substr() – Extract Part of String
$str = "Hello World";
echo substr($str, 0, 5);
Output: Hello
� (12) strcmp() – Compare Strings
echo strcmp("Hello", "Hello");
Output: 0 (means equal)