Jump to content

Include help


st0rmer

Recommended Posts

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.