PEHLA KALMA

PEHLA KALMA
Sanaullah Sajid Mukhtiar

Change text length in php and provide Read more link

Question:
I have text stored in the php variable $text. This text can be 100 or 1000 or 10000 words. As currently implemented, my page extends based on the text, but if the text is too long the page looks ugly.
I want to get the length of the text and limit the number of characters to maybe 500, and if the text exceeds this limit I want to provide a link saying, "Read more." If the "Read More" link is clicked, it will show a pop with all the text in $text.


How to limit lines in a string php


Answers:
< ? php
// strip tags to avoid breaking any html
//add your text in $string example 
$string = "My website www.engineersoftpk.com software php android apps Visual Basic";

$string = strip_tags($string);
//50 length of text limit change it
if (strlen($string) > 50) {

    // truncate string
    $stringCut = substr($string, 0, 50);

    // make sure it ends in a word so assassinate doesn't become ass...
    $string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... Read Mores'; 
}
echo $string;

? >