SlideShare a Scribd company logo
Strings
strings in php how to use different data types in string
strings in php how to use different data types in string
Single Quoted
• The simplest way to create a string is to enclose the string literal (i.e.
string characters) in single quotation marks ('), like this:
Double-quote strings
• Unlike single-quote strings, double-quote strings in PHP are capable
of processing special characters.
strings in php how to use different data types in string
strings in php how to use different data types in string
strings in php how to use different data types in string
We can perform several functions on string in PHP . The string manipulation functions are.
PHP Strings
A string is a sequence of characters, like "Hello world!".
we will look at some commonly used functions to manipulate strings.
strlen() - Return the Length of a String
The PHP strlen() function returns the length of a string.
str_word_count() - Count Words in a String
The PHP str_word_count() function counts the number of words in a string.
strrev() - Reverse a String
The PHP strrev() function reverses a string.
trim() function:
• This function allows us to remove whitespaces or strings from both
sides of a string.
strings in php how to use different data types in string
str_replace() - Replace Text Within a String
The PHP str_replace() function replaces some characters with some other characters in a string.
strtolower() function:
• This function converts a string into the lowercase string.
strtoupper() function:
• This function converts a string into the uppercase string.
Comparing Strings
PHP strcmp() Function
Comparing Strings
PHP strcmp() Function
Comparing Strings
The strcmp() function compares two strings.
The strcmp() function is binary-safe and case-sensitive.
Cleaning Strings
The trim() function removes whitespace and other predefined characters from both sides
of a string.
Related functions:
•ltrim() - Removes whitespace or other predefined characters from the left side of a
string
•rtrim() - Removes whitespace or other predefined characters from the right side of a
string
Cleaning Strings
Cleaning Strings
chop() Function
• The chop() function is used to remove whitespace or other predefined
character from the right end of a string.
• Syntax: chop(string,charlist);
• Example
<?php
$str = "Hello World!";
echo "Your string is :".$str."<br>";
echo "By using 'chop()' Functions is your string is: ".chop($str,"World!");
?>
Parameter Description Required/Optional
string the string to be
check
Required
charlist charlist parameter
is empty
Optional
Output:
Your string is :Hello
World!
By using 'chop()'
Functions is your
string is: Hello
PHP chunk_split() Function
• PHP chunk_split() function is used to splits a string into smaller parts
or chunks. The function does not alter the original string.
• Syntax: chunk_split(string,length,end)
<?php
$str = "Hello!;
echo "Your string is:".$str;
echo "By using 'chunk_split()' function your string is:".chunk_split($str,1,".
..");
?>
Parameter Description Required/Optional
string String to split Required
Length Specify the length of the
chunks. Default is 76
Optional
end Specify what to place at
the end each chunk.
Optional
Output:
Your string is: Hello
By using 'chunk_split()' function your string
is: H…e...l...l...o...!...
PHP type casting
• Type casting allows you to convert a value of one type to another.
To cast a value, you use the following type casting operators:
Which of the following functions is used to find
the first occurrence of a substring in a string?
• strlen()
• strpos()
• str_replace()
• str_split()
Which of the following functions is used to find
the first occurrence of a substring in a string?
• strlen()
• strpos()
• str_replace()
• str_split()
Which of the following functions is used to replace all
occurrences of a substring in a string with another substring?
• strlen()
• strpos()
• str_replace()
• str_split()
Which of the following functions is used to replace all
occurrences of a substring in a string with another substring?
• strlen()
• strpos()
• str_replace()
• str_split()
Which of the following functions is used to
count the number of words in a string?
• strlen()
• strpos()
• str_replace()
• str_word_count()
Which of the following functions is used to
count the number of words in a string?
• strlen()
• strpos()
• str_replace()
• str_word_count()
Which of the following is not a built-in PHP
function for working with strings?
• strlen()
• strpos()
• str_replace()
• str_split()
• strrev()
Which of the following is not a built-in PHP
function for working with strings?
• strlen()
• strpos()
• str_replace()
• str_split()
• strrev()
What is the following is the output of the following PHP code?
•
• $str = "Hello, world!";
• echo strlen($str);
• 13
What is the following is the output of the following PHP code?
• <?php
• $str = "Hello, world!";
• echo strpos($str, "world");
• ?>
• 7
What is the following is the output of the following PHP code?
• <?php
• $str = "Hello, world!";
• echo str_replace("world", "universe", $str);
• ?>
• Hello universe
What is the following is the output of the following PHP code?
• <?php
• $str = "Hello, world!";
• echo $str[0];
• ?>
• H

More Related Content

Similar to strings in php how to use different data types in string (20)

PPTX
String variable in php
chantholnet
 
PPTX
Php string function
Ravi Bhadauria
 
PPT
Geek Austin PHP Class - Session 2
jimbojsb
 
PPTX
PHP string-part 1
monikadeshmane
 
PPTX
Presentation on php string function part-1
Mysoftheaven (BD) Ltd.
 
PPTX
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
KEY
Fall 2011 PHP Class - Session 2
jimbojsb
 
PPT
Class 5 - PHP Strings
Ahmed Swilam
 
PPT
php 2 Function creating, calling, PHP built-in function
tumetr1
 
PPT
9780538745840 ppt ch03
Terry Yoast
 
PPTX
Php functions
JIGAR MAKHIJA
 
PPTX
PHP Strings and Patterns
Henry Osborne
 
PPT
Manipulating strings
Nicole Ryan
 
PDF
Php tutorial(w3schools)
Arjun Shanka
 
PDF
Php tutorialw3schools
rasool noorpour
 
PDF
lab4_php
tutorialsruby
 
PDF
lab4_php
tutorialsruby
 
PPT
String functions and operations
Mudasir Syed
 
PPTX
Strings cprogramminglanguagedsasheet.pptx
hyundaitvhamari
 
String variable in php
chantholnet
 
Php string function
Ravi Bhadauria
 
Geek Austin PHP Class - Session 2
jimbojsb
 
PHP string-part 1
monikadeshmane
 
Presentation on php string function part-1
Mysoftheaven (BD) Ltd.
 
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Fall 2011 PHP Class - Session 2
jimbojsb
 
Class 5 - PHP Strings
Ahmed Swilam
 
php 2 Function creating, calling, PHP built-in function
tumetr1
 
9780538745840 ppt ch03
Terry Yoast
 
Php functions
JIGAR MAKHIJA
 
PHP Strings and Patterns
Henry Osborne
 
Manipulating strings
Nicole Ryan
 
Php tutorial(w3schools)
Arjun Shanka
 
Php tutorialw3schools
rasool noorpour
 
lab4_php
tutorialsruby
 
lab4_php
tutorialsruby
 
String functions and operations
Mudasir Syed
 
Strings cprogramminglanguagedsasheet.pptx
hyundaitvhamari
 

More from vishal choudhary (20)

PPTX
Pixel to Percentage conversion Convert left and right padding of a div to per...
vishal choudhary
 
PPTX
esponsive web design means that your website (
vishal choudhary
 
PPTX
function in php using like three type of function
vishal choudhary
 
PPTX
data base connectivity in php using msql database
vishal choudhary
 
PPTX
software evelopment life cycle model and example of water fall model
vishal choudhary
 
PPTX
software Engineering lecture on development life cycle
vishal choudhary
 
PPTX
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
vishal choudhary
 
PPTX
web performnace optimization using css minification
vishal choudhary
 
PPTX
web performance optimization using style
vishal choudhary
 
PPTX
Data types and variables in php for writing and databse
vishal choudhary
 
PPTX
Data types and variables in php for writing
vishal choudhary
 
PPTX
Data types and variables in php for writing
vishal choudhary
 
PPTX
sofwtare standard for test plan it execution
vishal choudhary
 
PPTX
Software test policy and test plan in development
vishal choudhary
 
PPTX
function in php like control loop and its uses
vishal choudhary
 
PPTX
introduction to php and its uses in daily
vishal choudhary
 
PPTX
data type in php and its introduction to use
vishal choudhary
 
PPTX
PHP introduction how to create and start php
vishal choudhary
 
PPT
SE-Lecture1.ppt
vishal choudhary
 
PPT
SE-Testing.ppt
vishal choudhary
 
Pixel to Percentage conversion Convert left and right padding of a div to per...
vishal choudhary
 
esponsive web design means that your website (
vishal choudhary
 
function in php using like three type of function
vishal choudhary
 
data base connectivity in php using msql database
vishal choudhary
 
software evelopment life cycle model and example of water fall model
vishal choudhary
 
software Engineering lecture on development life cycle
vishal choudhary
 
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
vishal choudhary
 
web performnace optimization using css minification
vishal choudhary
 
web performance optimization using style
vishal choudhary
 
Data types and variables in php for writing and databse
vishal choudhary
 
Data types and variables in php for writing
vishal choudhary
 
Data types and variables in php for writing
vishal choudhary
 
sofwtare standard for test plan it execution
vishal choudhary
 
Software test policy and test plan in development
vishal choudhary
 
function in php like control loop and its uses
vishal choudhary
 
introduction to php and its uses in daily
vishal choudhary
 
data type in php and its introduction to use
vishal choudhary
 
PHP introduction how to create and start php
vishal choudhary
 
SE-Lecture1.ppt
vishal choudhary
 
SE-Testing.ppt
vishal choudhary
 
Ad

Recently uploaded (20)

PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PDF
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
PDF
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
PPTX
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
PPTX
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
PDF
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PDF
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
PDF
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PPTX
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
PDF
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PPTX
grade 8 week 2 ict.pptx. matatag grade 7
VanessaTaberlo
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
grade 8 week 2 ict.pptx. matatag grade 7
VanessaTaberlo
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Ad

strings in php how to use different data types in string

  • 4. Single Quoted • The simplest way to create a string is to enclose the string literal (i.e. string characters) in single quotation marks ('), like this:
  • 5. Double-quote strings • Unlike single-quote strings, double-quote strings in PHP are capable of processing special characters.
  • 9. We can perform several functions on string in PHP . The string manipulation functions are.
  • 10. PHP Strings A string is a sequence of characters, like "Hello world!". we will look at some commonly used functions to manipulate strings. strlen() - Return the Length of a String The PHP strlen() function returns the length of a string.
  • 11. str_word_count() - Count Words in a String The PHP str_word_count() function counts the number of words in a string.
  • 12. strrev() - Reverse a String The PHP strrev() function reverses a string.
  • 13. trim() function: • This function allows us to remove whitespaces or strings from both sides of a string.
  • 15. str_replace() - Replace Text Within a String The PHP str_replace() function replaces some characters with some other characters in a string.
  • 16. strtolower() function: • This function converts a string into the lowercase string.
  • 17. strtoupper() function: • This function converts a string into the uppercase string.
  • 20. Comparing Strings The strcmp() function compares two strings. The strcmp() function is binary-safe and case-sensitive.
  • 21. Cleaning Strings The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: •ltrim() - Removes whitespace or other predefined characters from the left side of a string •rtrim() - Removes whitespace or other predefined characters from the right side of a string
  • 24. chop() Function • The chop() function is used to remove whitespace or other predefined character from the right end of a string. • Syntax: chop(string,charlist); • Example <?php $str = "Hello World!"; echo "Your string is :".$str."<br>"; echo "By using 'chop()' Functions is your string is: ".chop($str,"World!"); ?> Parameter Description Required/Optional string the string to be check Required charlist charlist parameter is empty Optional Output: Your string is :Hello World! By using 'chop()' Functions is your string is: Hello
  • 25. PHP chunk_split() Function • PHP chunk_split() function is used to splits a string into smaller parts or chunks. The function does not alter the original string. • Syntax: chunk_split(string,length,end) <?php $str = "Hello!; echo "Your string is:".$str; echo "By using 'chunk_split()' function your string is:".chunk_split($str,1,". .."); ?> Parameter Description Required/Optional string String to split Required Length Specify the length of the chunks. Default is 76 Optional end Specify what to place at the end each chunk. Optional Output: Your string is: Hello By using 'chunk_split()' function your string is: H…e...l...l...o...!...
  • 26. PHP type casting • Type casting allows you to convert a value of one type to another. To cast a value, you use the following type casting operators:
  • 27. Which of the following functions is used to find the first occurrence of a substring in a string? • strlen() • strpos() • str_replace() • str_split()
  • 28. Which of the following functions is used to find the first occurrence of a substring in a string? • strlen() • strpos() • str_replace() • str_split()
  • 29. Which of the following functions is used to replace all occurrences of a substring in a string with another substring? • strlen() • strpos() • str_replace() • str_split()
  • 30. Which of the following functions is used to replace all occurrences of a substring in a string with another substring? • strlen() • strpos() • str_replace() • str_split()
  • 31. Which of the following functions is used to count the number of words in a string? • strlen() • strpos() • str_replace() • str_word_count()
  • 32. Which of the following functions is used to count the number of words in a string? • strlen() • strpos() • str_replace() • str_word_count()
  • 33. Which of the following is not a built-in PHP function for working with strings? • strlen() • strpos() • str_replace() • str_split() • strrev()
  • 34. Which of the following is not a built-in PHP function for working with strings? • strlen() • strpos() • str_replace() • str_split() • strrev()
  • 35. What is the following is the output of the following PHP code? • • $str = "Hello, world!"; • echo strlen($str); • 13
  • 36. What is the following is the output of the following PHP code? • <?php • $str = "Hello, world!"; • echo strpos($str, "world"); • ?> • 7
  • 37. What is the following is the output of the following PHP code? • <?php • $str = "Hello, world!"; • echo str_replace("world", "universe", $str); • ?> • Hello universe
  • 38. What is the following is the output of the following PHP code? • <?php • $str = "Hello, world!"; • echo $str[0]; • ?> • H