SlideShare a Scribd company logo
Strings
TYBSC Comp Sci.
Chapter 2- Functions & Strings
monica deshmane(H.V.Desai college) 1
Points to learn
• String
• Types of strings in PHP
• Printing functions
• Basic functions of string
monica deshmane(H.V.Desai college) 2
String types
• 1. Single quoted Strings ‘’
Ex. $str=‘hi’;
$str1=‘nhi’
echo “$str1”;
• 2. Double quoted String “ ”
Strings interpolate & expand by escape sequences.
• Variable Interpolation-
Interpolation is replacing variable names in string with values of those variables.
Ex.$str1=“nhi”
echo “$str1”;
monica deshmane(H.V.Desai college) 3
String types
• 3. Here Documents(heredoc)
heredoc allows multiline String.
<<< identifier is used in php for displaying string using heredoc.
<?php $str = <<< my_doc
‘This is an example.
This is used for multiline.’
my_doc;
echo $str;
?>
//may use ‘ or “ or no quotes.
• 4. New Documents(Newdoc)
this allows multiline String same as heredoc just put name in single quotes. Ex.
<?php $str = <<< ‘my_doc’….
monica deshmane(H.V.Desai college)
4
Printing Strings
1. Echo – This allows to print many values at a time.
echo "Hello Abcd";
echo ("Hello Abcd");
echo "Hello Abcd", "How are u?";
//echo ("Hello Abcd", "How are u?"); - not allowed
2. print() This function returns true or false boolean value.
if (print(“Hello PHP”))
{
echo “String is displayed successfully”;
}
monica deshmane(H.V.Desai college) 5
Printing Strings
3. printf() - function used to print formatted String output.
$str = “Abc”;
$age=20.5;
printf(“%s is %d years old”, $str, $age);
4.print_r() – function displays what is passed to it, It
will not convert everything into string as echo and
print().
$Student = array(‘name’ => ‘A’, ‘RollNo’ => 100,
‘Class’ => ‘TY’);
print_r($Student);
Output: Array ( [name] => A [RollNo] => 100 [Class] => TY )
monica deshmane(H.V.Desai college) 6
Printing Strings
5. var_dump() – It is preferred over print_r() for
debugging. This function displays PHP value in
human readable format.
Eg:
<?php
$b = 3.1;
$c = true;
var_dump($b, $c);
?>
Output:
float(3.1) bool(true)
monica deshmane(H.V.Desai college) 7
Printing Strings
var_dump(array('name' => John, 'age' => 35));
Output:
array(2) { ["name"]=> string(4) “John"
["age"]=> int(35) }
6.sprintf()
To print string with format
Ex. $str=sprintf(“hi %s is %s”,”this “,”php”);
Echo $str;
monica deshmane(H.V.Desai college) 8
revise
• Printing functions
1. Echo
2. Print
3. printf
4. Sprintf
5. Print_r
6. Var_dump
monica deshmane(H.V.Desai college) 9
Calculating length of String
strlen()
What we require to compute length of string?
Syntax:
count= strlen(String variable);
Example:
$len = strlen($str);
monica deshmane(H.V.Desai college) 10
Calculating length of String
$str = “Hello, world”;
$len = strlen($str);
monica deshmane(H.V.Desai college) 11
Accessing Individual Characters
$str = “Welcome”;
for ($i=0; $i < strlen($str); $i++)
{
printf(“%d is %s”,$i, $str{$i});
}
Removing Whitespaces
trim()
$str1 = ltrim($title);
//leading spaces
$str2 = rtrim($title);
//trailing spaces
$str3 = trim($title);//all spaces
monica deshmane(H.V.Desai college) 12
Removing Whitespaces
$title = “ Welcome “;
$str1 = ltrim($title); //leading spaces
$str2 = rtrim($title); //trailing spaces
$str3 = trim($title); //all spaces
echo “$str1 $str2 $str3”;
monica deshmane(H.V.Desai college) 13
Changing Case
strtolower($title));
strtoupper($title));
ucfirst($title));
ucwords($title));
monica deshmane(H.V.Desai college) 14
Changing Case
$title = “hELLO welcome“;
printf(strtolower($title)); //hello welcome
printf(strtoupper($title)); //HELLO WELCOME
printf(ucfirst($title)); //HELLO welcome
printf(ucwords($title)); //HELLO Welcome
Note:
ucfirst() works on first character of whole string and ucwords works on first
character of each words in the string to convert it in uppercase.
monica deshmane(H.V.Desai college) 15
End of Presentation
monica deshmane(H.V.Desai college) 16
Ad

More Related Content

What's hot (16)

Optionals Swift - Swift Paris Junior #3
Optionals Swift - Swift Paris Junior #3 Optionals Swift - Swift Paris Junior #3
Optionals Swift - Swift Paris Junior #3
LouiseFonteneau
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
tutorialsruby
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
Ahmed Swilam
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
Vineet Kumar Saini
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
Patrick Viafore
 
tutorial7
tutorial7tutorial7
tutorial7
tutorialsruby
 
A quick python_tour
A quick python_tourA quick python_tour
A quick python_tour
cghtkh
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
Pete McFarlane
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
Bozhidar Boshnakov
 
Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)
garux
 
PHP - Introduction to String Handling
PHP -  Introduction to  String Handling PHP -  Introduction to  String Handling
PHP - Introduction to String Handling
Vibrant Technologies & Computers
 
C Language Lecture 12
C Language Lecture 12C Language Lecture 12
C Language Lecture 12
Shahzaib Ajmal
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 
Optionals Swift - Swift Paris Junior #3
Optionals Swift - Swift Paris Junior #3 Optionals Swift - Swift Paris Junior #3
Optionals Swift - Swift Paris Junior #3
LouiseFonteneau
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
Ahmed Swilam
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
Patrick Viafore
 
A quick python_tour
A quick python_tourA quick python_tour
A quick python_tour
cghtkh
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
Pete McFarlane
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 
Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)
garux
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 

Similar to PHP string-part 1 (20)

Chap 3php array part 2
Chap 3php array part 2Chap 3php array part 2
Chap 3php array part 2
monikadeshmane
 
PHP teaching ppt for the freshers in colleeg.ppt
PHP teaching ppt for the freshers in colleeg.pptPHP teaching ppt for the freshers in colleeg.ppt
PHP teaching ppt for the freshers in colleeg.ppt
vvsofttechsolution
 
PHP-Overview.ppt
PHP-Overview.pptPHP-Overview.ppt
PHP-Overview.ppt
Akshay Bhujbal
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
mysthicrious
 
PHP-01-Overview.pptfreeforeveryonecomenow
PHP-01-Overview.pptfreeforeveryonecomenowPHP-01-Overview.pptfreeforeveryonecomenow
PHP-01-Overview.pptfreeforeveryonecomenow
oliverrobertjames
 
PHP - programing and pr155345345354553555
PHP - programing and pr155345345354553555PHP - programing and pr155345345354553555
PHP - programing and pr155345345354553555
KhaledLotfy12
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
NBACriteria2SICET
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
php_string.pdf
php_string.pdfphp_string.pdf
php_string.pdf
Sharon Manmothe
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
 
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdfPython Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
zayanchutiya
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
Sean Cribbs
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
Brahma Killampalli
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a Nutshell
Marcus Denker
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Andrea Telatin
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
Muthuganesh S
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Format String
Format StringFormat String
Format String
Wei-Bo Chen
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
 
Chap 3php array part 2
Chap 3php array part 2Chap 3php array part 2
Chap 3php array part 2
monikadeshmane
 
PHP teaching ppt for the freshers in colleeg.ppt
PHP teaching ppt for the freshers in colleeg.pptPHP teaching ppt for the freshers in colleeg.ppt
PHP teaching ppt for the freshers in colleeg.ppt
vvsofttechsolution
 
PHP-01-Overview.pptfreeforeveryonecomenow
PHP-01-Overview.pptfreeforeveryonecomenowPHP-01-Overview.pptfreeforeveryonecomenow
PHP-01-Overview.pptfreeforeveryonecomenow
oliverrobertjames
 
PHP - programing and pr155345345354553555
PHP - programing and pr155345345354553555PHP - programing and pr155345345354553555
PHP - programing and pr155345345354553555
KhaledLotfy12
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
 
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdfPython Cheatsheet_A Quick Reference Guide for Data Science.pdf
Python Cheatsheet_A Quick Reference Guide for Data Science.pdf
zayanchutiya
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
Sean Cribbs
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a Nutshell
Marcus Denker
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Andrea Telatin
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
Muthuganesh S
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Ad

More from monikadeshmane (18)

File system node js
File system node jsFile system node js
File system node js
monikadeshmane
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
monikadeshmane
 
Nodejs buffers
Nodejs buffersNodejs buffers
Nodejs buffers
monikadeshmane
 
Intsllation & 1st program nodejs
Intsllation & 1st program nodejsIntsllation & 1st program nodejs
Intsllation & 1st program nodejs
monikadeshmane
 
Nodejs basics
Nodejs basicsNodejs basics
Nodejs basics
monikadeshmane
 
Chap 5 php files part-2
Chap 5 php files   part-2Chap 5 php files   part-2
Chap 5 php files part-2
monikadeshmane
 
Chap 5 php files part 1
Chap 5 php files part 1Chap 5 php files part 1
Chap 5 php files part 1
monikadeshmane
 
Chap4 oop class (php) part 2
Chap4 oop class (php) part 2Chap4 oop class (php) part 2
Chap4 oop class (php) part 2
monikadeshmane
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1
monikadeshmane
 
Chap 3php array part4
Chap 3php array part4Chap 3php array part4
Chap 3php array part4
monikadeshmane
 
Chap 3php array part 3
Chap 3php array part 3Chap 3php array part 3
Chap 3php array part 3
monikadeshmane
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
monikadeshmane
 
PHP function
PHP functionPHP function
PHP function
monikadeshmane
 
php string-part 2
php string-part 2php string-part 2
php string-part 2
monikadeshmane
 
java script
java scriptjava script
java script
monikadeshmane
 
ip1clientserver model
 ip1clientserver model ip1clientserver model
ip1clientserver model
monikadeshmane
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
monikadeshmane
 
Chap1introppt1php basic
Chap1introppt1php basicChap1introppt1php basic
Chap1introppt1php basic
monikadeshmane
 
Ad

Recently uploaded (20)

To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 

PHP string-part 1

  • 1. Strings TYBSC Comp Sci. Chapter 2- Functions & Strings monica deshmane(H.V.Desai college) 1
  • 2. Points to learn • String • Types of strings in PHP • Printing functions • Basic functions of string monica deshmane(H.V.Desai college) 2
  • 3. String types • 1. Single quoted Strings ‘’ Ex. $str=‘hi’; $str1=‘nhi’ echo “$str1”; • 2. Double quoted String “ ” Strings interpolate & expand by escape sequences. • Variable Interpolation- Interpolation is replacing variable names in string with values of those variables. Ex.$str1=“nhi” echo “$str1”; monica deshmane(H.V.Desai college) 3
  • 4. String types • 3. Here Documents(heredoc) heredoc allows multiline String. <<< identifier is used in php for displaying string using heredoc. <?php $str = <<< my_doc ‘This is an example. This is used for multiline.’ my_doc; echo $str; ?> //may use ‘ or “ or no quotes. • 4. New Documents(Newdoc) this allows multiline String same as heredoc just put name in single quotes. Ex. <?php $str = <<< ‘my_doc’…. monica deshmane(H.V.Desai college) 4
  • 5. Printing Strings 1. Echo – This allows to print many values at a time. echo "Hello Abcd"; echo ("Hello Abcd"); echo "Hello Abcd", "How are u?"; //echo ("Hello Abcd", "How are u?"); - not allowed 2. print() This function returns true or false boolean value. if (print(“Hello PHP”)) { echo “String is displayed successfully”; } monica deshmane(H.V.Desai college) 5
  • 6. Printing Strings 3. printf() - function used to print formatted String output. $str = “Abc”; $age=20.5; printf(“%s is %d years old”, $str, $age); 4.print_r() – function displays what is passed to it, It will not convert everything into string as echo and print(). $Student = array(‘name’ => ‘A’, ‘RollNo’ => 100, ‘Class’ => ‘TY’); print_r($Student); Output: Array ( [name] => A [RollNo] => 100 [Class] => TY ) monica deshmane(H.V.Desai college) 6
  • 7. Printing Strings 5. var_dump() – It is preferred over print_r() for debugging. This function displays PHP value in human readable format. Eg: <?php $b = 3.1; $c = true; var_dump($b, $c); ?> Output: float(3.1) bool(true) monica deshmane(H.V.Desai college) 7
  • 8. Printing Strings var_dump(array('name' => John, 'age' => 35)); Output: array(2) { ["name"]=> string(4) “John" ["age"]=> int(35) } 6.sprintf() To print string with format Ex. $str=sprintf(“hi %s is %s”,”this “,”php”); Echo $str; monica deshmane(H.V.Desai college) 8
  • 9. revise • Printing functions 1. Echo 2. Print 3. printf 4. Sprintf 5. Print_r 6. Var_dump monica deshmane(H.V.Desai college) 9
  • 10. Calculating length of String strlen() What we require to compute length of string? Syntax: count= strlen(String variable); Example: $len = strlen($str); monica deshmane(H.V.Desai college) 10
  • 11. Calculating length of String $str = “Hello, world”; $len = strlen($str); monica deshmane(H.V.Desai college) 11 Accessing Individual Characters $str = “Welcome”; for ($i=0; $i < strlen($str); $i++) { printf(“%d is %s”,$i, $str{$i}); }
  • 12. Removing Whitespaces trim() $str1 = ltrim($title); //leading spaces $str2 = rtrim($title); //trailing spaces $str3 = trim($title);//all spaces monica deshmane(H.V.Desai college) 12
  • 13. Removing Whitespaces $title = “ Welcome “; $str1 = ltrim($title); //leading spaces $str2 = rtrim($title); //trailing spaces $str3 = trim($title); //all spaces echo “$str1 $str2 $str3”; monica deshmane(H.V.Desai college) 13
  • 15. Changing Case $title = “hELLO welcome“; printf(strtolower($title)); //hello welcome printf(strtoupper($title)); //HELLO WELCOME printf(ucfirst($title)); //HELLO welcome printf(ucwords($title)); //HELLO Welcome Note: ucfirst() works on first character of whole string and ucwords works on first character of each words in the string to convert it in uppercase. monica deshmane(H.V.Desai college) 15
  • 16. End of Presentation monica deshmane(H.V.Desai college) 16