View more option in simple php

in PHP Code / No Comments

Hi friends,

This is very simple post, but usually it will be helpful for freshers( newly learning PHP ) . Suppose we developed a news module in php code.

1) In the home page we have to display some content only.

2) When we click on full view then display the whole content.

For this requirement, follow the below code:

$body = (strlen($content) > 200)? substr($content,0,197). ‘…’ : $content;

This is first check the content length is more than 200 characters then it is display 197 characters and remaining with three dots ( . . . )

Hope that it will be useful.

With more than 9 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ...Contact : [email protected]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>