PHP substr() function

PHP substr() function will substract or returns the portion of string specified by the start and length parameters.
substr($string , int $start [, int $length ] )

  1. <?php
  2. $sub = substr("abcdef", -2);    // returns "ef", -2 represent starting from 2 character back
  3. $sub = substr("abcdef", -3, 1); // returns "d", -3 represent starting from 3 character back and 1 the length of the substraction
  4. echo substr('abcdef', 0, 3);  // returns "abc", starting from 0 to 3
  5.  
  6. // you can substract only one character
  7. $string = 'abcdef';
  8. echo $string[3]; // returns "d", the third character
  9. ?>

No related php tutorials.

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top

Leave a Reply