st0rmer Posted October 14, 2007 Share Posted October 14, 2007 I am including a php file into a webpage, but the problem i am having is i want to put a limit to the number of characters before it says 'read more' Its an article for my site, and it'll be on my homepage so i want it to be a certain length only before it gives the 'read more' link to the full articles Does anyone know how i can set a limit to the length of the articles before it gives the read more link Thanks (BTW, i am no expert in PHP, i just started it two weeks ago) Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/ Share on other sites More sharing options...
Orio Posted October 14, 2007 Share Posted October 14, 2007 The easiest way is by using substr(): <?php function cut_text($text, $length) { $real_len = strlen($text); $length = ($length <= $len) ? $length : $len; return substr($text, 0, $length)."... <a href=...>Read More!</a>"; } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/#findComment-369165 Share on other sites More sharing options...
jd2007 Posted October 14, 2007 Share Posted October 14, 2007 pls post code...i'll help u... Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/#findComment-369168 Share on other sites More sharing options...
st0rmer Posted October 14, 2007 Author Share Posted October 14, 2007 Heres the code: <? include('header.php'); include('variables.php'); echo $pagetitle; echo $home; include('header2.php'); ?> <!-- End Header 2 --> <div class="containerbody"> <div id="subpanel">Latest</div> <? include ('hosting/article_name.php'); ?> <!-- End Mid Section--> <? include('navigation_footer.php'); ?> and its the hosting/article_name.php file i want to limit @ Orio, how would i adapt that code with this? Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/#findComment-369171 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 You can't limit an include, you can however limit text using substr. Replace your call to include with.... echo substr(get_file_contents('hosting/article_name.php'),0,200); // change 200 to the length you wish. Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/#findComment-369175 Share on other sites More sharing options...
st0rmer Posted October 14, 2007 Author Share Posted October 14, 2007 I have tried that thorpe, but i get this error: Fatal error: Call to undefined function get_file_contents() in /home/myaccount/public_html/index.php on line 14 Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/#findComment-369178 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Then you'll need to use fread. Quote Link to comment https://forums.phpfreaks.com/topic/73185-include-help/#findComment-369185 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.