Grab the RSS feed

How to replace the long text with dots

In php we can easily replace the long text with the dots.

Here we use the substr function in PHP.

The below example shows the program for that….

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
&lthtml xmlns="http://www.w3.org/1999/xhtml" >
&lthead >
&ltmeta http-equiv="Content-Type" content="text/html; charset=utf-8" / >
&lttitle &gtUntitled Document</title >
</head >

&ltbody >
<?
$message="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

if(strlen($message) &gt15)
{
$listedword=substr($message,0,15);
echo $listedword."...";
}
else
{
echo $message;
} 
? >
</body >
</html >

The output is
ABCDEFGHIJKLMNO...
The first fifteen letters are printed and the remaining with dots…

For more information visit

For more information

Leave the comments to improve us..

Click Download this as a word document

2 comments:

  • Kevin said...

    Thank you for the code, it helped greatly.

    I had one question though:

    If $message="techno tiger website"; Then the output is "techno tiger we...".

    Is it possible to write code that will not cut words in half? So for example the code output would be "techno tiger..."?

    Thanks.

    technotiger said...

    Pleae use the wordwrap functionality.

    Refer http://php.net/manual/en.function.wordwrap.php

  •  
    Real Time Web Analytics