SlideShare a Scribd company logo
Instruction By:

          Dr. Bou
eun   Chhun             1
Content:

1. String Variable
2. Concatenate Operators
3. String with Single and Double
Quote
4. String with heredoc
5. The PHP strlen() function
6. The PHP strpos() function
7. The str_replace function
8. The strtoupper() function
9. The ucfirst() function
10. The trim() function            2
11. The strtolower() function
String Variable
        String variables are used for values that
         contain characters.
        After we have created a string variable we
         can manipulate it.
        A string can be used directly in a function
         or it can be stored in a variable.
        Here is PHP script with string value
             <?php
                    $str=‚This is String in PHP.‛;
                    echo $str;
             ?>
        Output of the above script are:
             This is string in PHP                     3
The PHP Concatenation Operator

        There is only one string operator in PHP.
        The concatenation operator (.) is used to
         join two string values together.
        Below is the example of string
         concatenation
             <?php
                   $txt1="Hello world!";
                   $txt2="What a nice day!";
                   echo $txt1 . " " . $txt2;
             ?>
        The result of the above
             Hello world What a nice day!
                                                     4
String with Single and Double
quote
    There are two way when you can specify a string in
     php single quote and double quote.
    Single quoted strings are treated almost
     literally.
    double quoted strings replace variables with their
     values as well as specially interpreting certain
     character sequences.
    Here is an example
         <?php
               $variable=‚name‛;
               $literally=‘My $variable will not print
   n’;
               print($literally);
               $literally=‚My $variable will print n‛;
                                                          5
               print($literally);
 The result of the above code will be
       My $variable will not print!n
       My name will print
 String with double quote will process in both two way:
       1. Certain character sequences beginning with backslash
          () are replaced with special characters
       2. Variable names (starting with $) are replaced with string
                 representations of their values.
 The escape-sequence replacements are:
       n is replaced by the newline character
       r is replaced by the carriage-return character
       t is replaced by the tab character
       $ is replaced by the dollar sign itself ($)
       " is replaced by a single double-quote (")
        is replaced by a single backslash ()                       6
String with Heredoc
   You can assign multiple lines to a single string
    variable using heredoc .
   See the example below

       <?php
             echo <<<END
             This uses the "here document" syntax to
       output
             multiple lines with variable
       interpolation. Note
             that the here document terminator must
       appear       on a
             line with just a semicolon. no extra
       whitespace!                                     7
             <br />
 In code above after heredoc must be follow by
  some identifier for example END and must be
  end with the same identifier as the start one
  with semiconlon sign
 Even though using heredoc is difficult and can
  Couse some problem.
 Note that the closing sequence END; must occur
  on a line by itself and cannot be indented.




                                                   8
The PHP strlen() Function

    Strlen() function used to return the length of
     the string
          example:
                <?php
                         $str=‚Welcome back to PHP‛;
                         echo strlen($str);
                ?>
    Result will be
                19
    The length of a string is often used in loops or other
     functions, when it is important to know when the
     string ends. (i.e. in a loop, we would want to stop      9
     the loop after the last character in the string).
The strops() Function

     Strpos() function is used to return the search
      of character with in the string.
     If match is found, function will return the
      position of the first character of the match
      word.
          example:
                <?php
                      echo strpos(‛Welcome back to
                                  PHP‛,‛PHP‛);
                ?>
     The result of the above script is follow
                16
     The resean is that it return only the first
                                                       10
       character of the whole word .
The str_replace function

    The str_replace function is use to search and
     replace the search result with the new word.
    If no word match it will return the original
     word.
          example
               <?php
                     $str=‚Welcome back to PHP.‛;
                     echo str_replace(‚PHP‛,‛PHP
                           Function‛,$str);
               ?>
    This will search for the word PHP and replace
      with the word PHP Function.
    The result is:                                  11
                     Welcome back to PHP Function.
The strtoupper() Function

 The strtoupper() function is used to convert all
  lowercase of the string word or sentence to
  uppercase.
      example
            <?php
                  $str=‚start your first php with
w3school.‛;
                  echo strtoupper($str);
            ?>
 Here is the result
                  START YOUR FIRST PHP WITH
            W3SCHOOL.
                                                     12
The strtolower() Function

     The strtolower() function is used to convert all
      uppercase string to lowercase.
          example
                <?php
                      $str=‚START YOUR FIRST PHP WITH
                      W3SCHOOL.‛;
                      echo strtolower($str);
                ?>
     Here is the result
                start your first php with w3school.


                                                         13
The ucfirst() function

    Ucfirst() function used to capital the first letter of
     the first word in the whole string.
         example
                <?php
                      $str=‚using ucfirst() function.‛;
                      echo($str);
                ?>
    The result is
                Using ucfirst() function.


                                                              14
The trim() function
     Trim() function strip a string of white space in
      front and at the end of the whole string.
          example
                <?php
                      $str=‚ Welcome! ‛;
                      echo($str);
                ?>
     The above will result as below
                      Welcome!




                                                         15
Referent:

1. http://www.w3schools.com/php/php_string.asp
2. http://www.tutorialspoint.com/php/php_variable_types.htm




                                                              16
Ad

More Related Content

What's hot (16)

Subroutines
SubroutinesSubroutines
Subroutines
Krasimir Berov (Красимир Беров)
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
Varadharajan Mukundan
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
Sopan Shewale
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
rhshriva
 
Php basics
Php basicsPhp basics
Php basics
hamfu
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
Sean Cribbs
 
Php Chapter 4 Training
Php Chapter 4 TrainingPhp Chapter 4 Training
Php Chapter 4 Training
Chris Chubb
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
lichtkind
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
 
Unit vii wp ppt
Unit vii wp pptUnit vii wp ppt
Unit vii wp ppt
Bhavsingh Maloth
 
1 the ruby way
1   the ruby way1   the ruby way
1 the ruby way
Luis Doubrava
 
php string part 4
php string part 4php string part 4
php string part 4
monikadeshmane
 
Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web Programming
Amirul Azhar
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
Dave Cross
 
Perl
PerlPerl
Perl
RaviShankar695257
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 

Similar to String variable in php (20)

String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeString handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
php_string.pdf
php_string.pdfphp_string.pdf
php_string.pdf
Sharon Manmothe
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
Php
PhpPhp
Php
shakubar sathik
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
How to run PHP code in XAMPP.docx (1).pdf
How to run PHP code in XAMPP.docx (1).pdfHow to run PHP code in XAMPP.docx (1).pdf
How to run PHP code in XAMPP.docx (1).pdf
rajeswaria21
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
Deepak Rajput
 
Tokens in php (php: Hypertext Preprocessor).pptx
Tokens in  php (php: Hypertext Preprocessor).pptxTokens in  php (php: Hypertext Preprocessor).pptx
Tokens in php (php: Hypertext Preprocessor).pptx
BINJAD1
 
advancing in php programming part four.pptx
advancing in php programming part four.pptxadvancing in php programming part four.pptx
advancing in php programming part four.pptx
KisakyeDennis
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
Niladri Karmakar
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
Gnugroup India
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
Nicole Ryan
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
Open Gurukul
 
PHP Lec 2.pdfsssssssssssssssssssssssssss
PHP Lec 2.pdfsssssssssssssssssssssssssssPHP Lec 2.pdfsssssssssssssssssssssssssss
PHP Lec 2.pdfsssssssssssssssssssssssssss
ksjawyyy
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeString handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
How to run PHP code in XAMPP.docx (1).pdf
How to run PHP code in XAMPP.docx (1).pdfHow to run PHP code in XAMPP.docx (1).pdf
How to run PHP code in XAMPP.docx (1).pdf
rajeswaria21
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
Deepak Rajput
 
Tokens in php (php: Hypertext Preprocessor).pptx
Tokens in  php (php: Hypertext Preprocessor).pptxTokens in  php (php: Hypertext Preprocessor).pptx
Tokens in php (php: Hypertext Preprocessor).pptx
BINJAD1
 
advancing in php programming part four.pptx
advancing in php programming part four.pptxadvancing in php programming part four.pptx
advancing in php programming part four.pptx
KisakyeDennis
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
Nicole Ryan
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
Open Gurukul
 
PHP Lec 2.pdfsssssssssssssssssssssssssss
PHP Lec 2.pdfsssssssssssssssssssssssssssPHP Lec 2.pdfsssssssssssssssssssssssssss
PHP Lec 2.pdfsssssssssssssssssssssssssss
ksjawyyy
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Ad

Recently uploaded (20)

Rococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th centuryRococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th century
Gema
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Rococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th centuryRococo versus Neoclassicism. The artistic styles of the 18th century
Rococo versus Neoclassicism. The artistic styles of the 18th century
Gema
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Lecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptxLecture 1 Introduction history and institutes of entomology_1.pptx
Lecture 1 Introduction history and institutes of entomology_1.pptx
Arshad Shaikh
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Ad

String variable in php

  • 1. Instruction By: Dr. Bou eun Chhun 1
  • 2. Content: 1. String Variable 2. Concatenate Operators 3. String with Single and Double Quote 4. String with heredoc 5. The PHP strlen() function 6. The PHP strpos() function 7. The str_replace function 8. The strtoupper() function 9. The ucfirst() function 10. The trim() function 2 11. The strtolower() function
  • 3. String Variable  String variables are used for values that contain characters.  After we have created a string variable we can manipulate it.  A string can be used directly in a function or it can be stored in a variable.  Here is PHP script with string value <?php $str=‚This is String in PHP.‛; echo $str; ?>  Output of the above script are: This is string in PHP 3
  • 4. The PHP Concatenation Operator  There is only one string operator in PHP.  The concatenation operator (.) is used to join two string values together.  Below is the example of string concatenation <?php $txt1="Hello world!"; $txt2="What a nice day!"; echo $txt1 . " " . $txt2; ?>  The result of the above Hello world What a nice day! 4
  • 5. String with Single and Double quote  There are two way when you can specify a string in php single quote and double quote.  Single quoted strings are treated almost literally.  double quoted strings replace variables with their values as well as specially interpreting certain character sequences.  Here is an example <?php $variable=‚name‛; $literally=‘My $variable will not print n’; print($literally); $literally=‚My $variable will print n‛; 5 print($literally);
  • 6.  The result of the above code will be My $variable will not print!n My name will print  String with double quote will process in both two way: 1. Certain character sequences beginning with backslash () are replaced with special characters 2. Variable names (starting with $) are replaced with string representations of their values.  The escape-sequence replacements are: n is replaced by the newline character r is replaced by the carriage-return character t is replaced by the tab character $ is replaced by the dollar sign itself ($) " is replaced by a single double-quote (") is replaced by a single backslash () 6
  • 7. String with Heredoc  You can assign multiple lines to a single string variable using heredoc .  See the example below <?php echo <<<END This uses the "here document" syntax to output multiple lines with variable interpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! 7 <br />
  • 8.  In code above after heredoc must be follow by some identifier for example END and must be end with the same identifier as the start one with semiconlon sign  Even though using heredoc is difficult and can Couse some problem.  Note that the closing sequence END; must occur on a line by itself and cannot be indented. 8
  • 9. The PHP strlen() Function  Strlen() function used to return the length of the string example: <?php $str=‚Welcome back to PHP‛; echo strlen($str); ?>  Result will be 19  The length of a string is often used in loops or other functions, when it is important to know when the string ends. (i.e. in a loop, we would want to stop 9 the loop after the last character in the string).
  • 10. The strops() Function  Strpos() function is used to return the search of character with in the string.  If match is found, function will return the position of the first character of the match word. example: <?php echo strpos(‛Welcome back to PHP‛,‛PHP‛); ?>  The result of the above script is follow 16  The resean is that it return only the first 10 character of the whole word .
  • 11. The str_replace function  The str_replace function is use to search and replace the search result with the new word.  If no word match it will return the original word. example <?php $str=‚Welcome back to PHP.‛; echo str_replace(‚PHP‛,‛PHP Function‛,$str); ?>  This will search for the word PHP and replace with the word PHP Function.  The result is: 11 Welcome back to PHP Function.
  • 12. The strtoupper() Function  The strtoupper() function is used to convert all lowercase of the string word or sentence to uppercase. example <?php $str=‚start your first php with w3school.‛; echo strtoupper($str); ?>  Here is the result START YOUR FIRST PHP WITH W3SCHOOL. 12
  • 13. The strtolower() Function  The strtolower() function is used to convert all uppercase string to lowercase. example <?php $str=‚START YOUR FIRST PHP WITH W3SCHOOL.‛; echo strtolower($str); ?>  Here is the result start your first php with w3school. 13
  • 14. The ucfirst() function  Ucfirst() function used to capital the first letter of the first word in the whole string. example <?php $str=‚using ucfirst() function.‛; echo($str); ?>  The result is Using ucfirst() function. 14
  • 15. The trim() function  Trim() function strip a string of white space in front and at the end of the whole string. example <?php $str=‚ Welcome! ‛; echo($str); ?>  The above will result as below Welcome! 15