strrpos.php : strrpos « String « PHP






strrpos.php

 
<?php
   $limit = 100;

$summary = <<< summary
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
summary;

   if (strlen($summary) > $limit) 
      $summary = substr($summary, 0, strrpos(substr($summary, 0, $limit), ' ')) . '...';
   echo $summary;
?>
  
  








Related examples in the same category

1.strrpos() function locates the last occurrence of character in string.
2.Using several functions together to extract a portion of a string
3.A third parameter to strpos( ) that allows us to specify where to start searching from
4.Finding a substring with strpos()
5.Finding the Position of a Substring with strpos()
6.int strpos ( string haystack, mixed needle [, int offset] ) returns the index of the beginning of a substring's first occurrence within a string
7.strpos
8.strpos( ) will return false (as opposed to -1)
9.strpos() function finds the position of the first occurrence in string.
10.Return String found at position 22
11.Using String Matching vs. Pattern Matching