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" > <html xmlns="http://www.w3.org/1999/xhtml" > <head > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" / > <title >Untitled Document</title > </head > <body > <? $message="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if(strlen($message) >15) { $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:
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.
Pleae use the wordwrap functionality.
Refer http://php.net/manual/en.function.wordwrap.php