SlideShare a Scribd company logo
1 of 16
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

More Related Content

What's hot

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 PHPAhmed 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 TypingPatrick Viafore
 
A quick python_tour
A quick python_tourA quick python_tour
A quick python_tourcghtkh
 
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 tomorrowPete McFarlane
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon 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 PythonistRaji Engg
 

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
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
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
 
tutorial7
tutorial7tutorial7
tutorial7
 
A quick python_tour
A quick python_tourA quick python_tour
A quick python_tour
 
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
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)
 
PHP - Introduction to String Handling
PHP -  Introduction to  String Handling PHP -  Introduction to  String Handling
PHP - Introduction to String Handling
 
C Language Lecture 12
C Language Lecture 12C Language Lecture 12
C Language Lecture 12
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 

Similar to PHP String Functions

Chap 3php array part 2
Chap 3php array part 2Chap 3php array part 2
Chap 3php array part 2monikadeshmane
 
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 WayUtkarsh 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 NeedsRoy Zimmer
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangSean Cribbs
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellMarcus 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, loopingMuthuganesh 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 3Mohd Harris Ahmad Jaal
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Ruby, muito mais que reflexivo
Ruby, muito mais que reflexivoRuby, muito mais que reflexivo
Ruby, muito mais que reflexivoFabio Kung
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)monikadeshmane
 

Similar to PHP String Functions (20)

Chap 3php array part 2
Chap 3php array part 2Chap 3php array part 2
Chap 3php array part 2
 
PHP-Overview.ppt
PHP-Overview.pptPHP-Overview.ppt
PHP-Overview.ppt
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
 
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
 
php_string.pdf
php_string.pdfphp_string.pdf
php_string.pdf
 
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
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a Nutshell
 
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...
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
 
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
 
Format String
Format StringFormat String
Format String
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Ruby, muito mais que reflexivo
Ruby, muito mais que reflexivoRuby, muito mais que reflexivo
Ruby, muito mais que reflexivo
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 

More from monikadeshmane

More from monikadeshmane (17)

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

Recently uploaded

Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 

Recently uploaded (20)

Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 

PHP String Functions

  • 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