View more option in simple php

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.

Anil Kumar Panigrahi

With more than 10 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]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *