wispas Posted January 5, 2010 Share Posted January 5, 2010 Like the title says, i want to have a paragraph of text and shorten it to 25 characters... it will have a read more button and when clicked it will expand all of the text. not sure if this is php... if so does anyone know what this is called and how this is done. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/187254-shorten-text-click-and-expand/ Share on other sites More sharing options...
monkeypaw201 Posted January 5, 2010 Share Posted January 5, 2010 I think it would more along the lines of javascript (http://llizard.etherwork.net/cwc/showhide.html) and some php (http://php.net/manual/en/function.substr.php) Quote Link to comment https://forums.phpfreaks.com/topic/187254-shorten-text-click-and-expand/#findComment-988879 Share on other sites More sharing options...
oni-kun Posted January 5, 2010 Share Posted January 5, 2010 Like the title says, i want to have a paragraph of text and shorten it to 25 characters... it will have a read more button and when clicked it will expand all of the text. not sure if this is php... if so does anyone know what this is called and how this is done. thanks! You can shorten it, and even add a link making it truly dynamic with PHP. But yeah, JS will be needed to expand the actual area. $string = 'I am a long title, Shorten me to 30 characters and it will be interesting to see the result'; function shorten($string, $length, $id) { if (strlen($string) > $length) { $string = substr($string, 0, $length)."<a onClick='expandText(".$id.")'...</a>"; } return $string; } $shorttitle = shorten($string, 30, 'div1'); echo $shortitle; The onClick code won't work, but I showed you an example of how you can pass the id of the string you want to shorten, or you can just define it yourself (simpler if you need be) Quote Link to comment https://forums.phpfreaks.com/topic/187254-shorten-text-click-and-expand/#findComment-988891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.