0% found this document useful (0 votes)
3 views3 pages

String

String manipulation involves operations on strings such as finding length, changing case, extracting parts, replacing text, and comparing strings. The document lists important string functions in PHP, including strlen(), str_word_count(), strrev(), strpos(), and others, each with a brief description and example. These functions allow developers to perform various tasks related to string handling efficiently.

Uploaded by

122veeransh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

String

String manipulation involves operations on strings such as finding length, changing case, extracting parts, replacing text, and comparing strings. The document lists important string functions in PHP, including strlen(), str_word_count(), strrev(), strpos(), and others, each with a brief description and example. These functions allow developers to perform various tasks related to string handling efficiently.

Uploaded by

122veeransh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🔹 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)

You might also like