Display dot if the string is too long in PHP

Description

The following code shows how to display dot if the string is too long.

Example


<?php/*  ww w. j av a 2 s.  c om*/
   // Limit $summary to how many characters?
   $limit = 10;

$summary = <<< summary
this is a test from java2s.com
this is a test from java2s.com
this is a test from java2s.com
this is a test from java2s.com
this is a test from java2s.com
this is a test from java2s.com
this is a test from java2s.com
this is a test from java2s.com
summary;

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

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone