Page 1 of 4 123 ... LastLast
Results 1 to 10 of 34

Thread: Day 3 - String Operations - Become PHP Expert in 30 days.

  1. #1
    Join Date
    Sep 2003
    Posts
    3,040

    Default Day 3 - String Operations - Become PHP Expert in 30 days.

    String Operations



    On Day 2, we learned how to use strings. Today we will learn more string related operations.

    PHP provide various functions that help us to work with strings.

    Finding Length of a String

    strlen() function is used to find length of a string.

    strlen.php

    PHP Code:
    <?php

    $companyName 
    'FlashWebHost.com';

    echo 
    strlen($companyName);
    Convert Text to Upper Case.

    PHP Provide strtoupper() function to convert strings (text) to upper case.

    strtoupper.php

    PHP Code:
    <?php

    $companyName 
    'FlashWebHost.com';

    echo 
    strtoupper($companyName);
    Convert Text to Lower Case.

    strtolower() function can convert text to lower case.

    strtolower.php

    PHP Code:
    <?php

    $companyName 
    'FlashWebHost.com';

    echo 
    strtolower($companyName);
    Convert First Letter of Words to Upper Case

    ucwords() convert first letter of each word to upper case.

    ucwords.php

    PHP Code:
    <?php

    $myCar 
    'I have a red car';

    $myCar ucwords($myCar);

    echo 
    $myCar;

    echo 
    '<br>';

    $myBus 'I HAVE A RED BUS';

    $myBus ucwords($myBus);

    echo 
    $myBus;
    Replacing Text

    str_replace() function in allow you to replace text in a string.

    str_replace.php

    PHP Code:
    <?php

    $myCar 
    'I have a red car';

    $myCar str_replace('red''white'$myCar);

    echo 
    $myCar;

    Here str_replace() find text 'red' and replace it with 'white' inside variable $myCar.




    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  2. #2
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/world.php

    Code:
    <?php
    
    echo strlen ('Beautiful World');

  3. #3
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sherlyk View Post
    http://php.flashwebhost.com/sherly/world.php

    Code:
    <?php
    
    echo strlen ('Beautiful World');
    Nice, you can directly pass string to strlen() function.

    Code:
    <?php
    
    $length = strlen ('Beautiful World');
    
    echo $length;
    Here we store the number rrturned by strlen() function to variable $length. Then echo it.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  4. #4
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/mother.php

    Code:
    <?php
    $str = 'Mother is the name for God in the lips and hearts of little children';
    $str = strtoupper($str);
    echo $str; // MOTHER IS THE NAME FOR GOD IN THE LIPS AND HEARTS OF LITTLE CHILDREN

  5. #5
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    Hi,

    http://php.flashwebhost.com/annie/ucfirst.php



    Code:
    <?php
    $myMobile = 'i have a samsung galaxy s3';
    $myMobile = ucwords ($myMobile);
    echo $myMobile;
    echo '<br>';
    
    $myCar = 'i have a red car' ;
    $myCar = ucwords ($myCar);
    echo $myCar;
    echo '<br>';
    
    $bestFilm = 'RAAMJI RAO SPEAKING';
    $bestFilm = ucwords ($bestFilm);
    echo $bestFilm;

  6. #6
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I got error http://php.flashwebhost.com/sherly/school.php

    Code:
    Fatal error:  Call to undefined function strtolower() in /home/fwhphp/public_html/sherly/school.php on line 5
    Code:
    <?php
    
    $schoolName = 'Little Flower School';
    
    echo strtolower ($schoolName);
    Last edited by sherlyk; 05-10-2014 at 06:00 AM.

  7. #7
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sherlyk View Post
    I got error http://php.flashwebhost.com/sherly/school.php

    Code:
    Fatal error:  Call to undefined function strlower() in /home/fwhphp/public_html/sherly/school.php on line 5
    Code:
    <?php
    
    $schoolName = 'Little Flower School';
    
    echo strlower ($schoolName);
    function name is strtolower(), in the code to is missing.

    find

    Code:
    strlower
    Replace With

    Code:
    strtolower
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  8. #8
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/bizhat.php

    Code:
    <?php
    
    $string1 = 'WELCOME TO BIZHAT.COM';
    echo strtolower($string1);

  9. #9
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 3 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/strlen.php

    Code:
    <?php
    
    
    $movieName = 'Peruvannapurathe Visheshangal' ;
    
    
    echo strlen($movieName) ;

  10. #10
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/friend.php

    Code:
    $string_Quotes = 'A friend is someone who knows all about you and still loves you';
    $string_Quotes = ucfirst($string_Quotes);
    echo $string_Quotes;
    Last edited by sherlyk; 05-10-2014 at 06:28 AM.

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •