Return Part Of A String

 
 
Returns the portion of string specified by the start and length parameters. If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.
 
 
  1. <?php

  2. echo substr('abcdef', 1);     // bcdef

  3. echo substr('abcdef', 1, 3)// bcd

  4. echo substr('abcdef', 0, 4)// abcd

  5. echo substr('abcdef', 0, 8)// abcdef

  6. echo substr('abcdef', -1, 1); // f

  7.  

  8. // Accessing single characters in a string

  9. // can also be achived using "curly braces"

  10. $string = 'abcdef';

  11. echo $string{0};                 // a

  12. echo $string{3};                 // d

  13. echo $string{strlen($string)-1}; // f

  14.  

  15. ?>
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 3rd Apr 2008
  Rating : No Rating
  Accessed  :  4361
  Submitted by :  goldeekhan
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related PHP Source Codes
  • Spring
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string

  • Copyright © 2013 VisualBuilder. All rights reserved