Page 1 of 1

Need to limit amount of text loaded into a cell

Posted: Wed Jun 17, 2009 1:56 pm
by cnl83
I have a some news that im loading into a cell. You can see the actual page here. (take a look at the section towards the bottom that says Todays hot news). http://www.poshinteriors.com/09/news/

I only want to be able to display no more than 250 Characters. Does anyone know a nifty way to do this in a cell?
fastnews-code.php is the form that actually loads the text from a text document. Would it be eaiser to load the first 250 characters from the text file, or do it the way im doing it? If so..how :)

Code: Select all

   <td height="110"></td>
    <td colspan="2" rowspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="imported/news.gif">
      <!--DWLayoutTable-->
      <tr>
        <td width="32" height="38">&nbsp;</td>
        <td width="258">&nbsp;</td>
        <td width="11">&nbsp;</td>
      </tr>
      <tr>
        <td height="89">&nbsp;</td>
        <td valign="top"><p align="left"><?php
include_once( dirname(__FILE__) . '/fastnews-code.php' );
$fn = new fastNews();
echo $fn->display();
?></a> </p></td>
          <td>&nbsp;</td>
      </tr>
     
    </table></td>

Re: Need to limit amount of text loaded into a cell

Posted: Wed Jun 17, 2009 7:26 pm
by Benjamin
:arrow: Moved to PHP - Code :?

Re: Need to limit amount of text loaded into a cell

Posted: Wed Jun 17, 2009 8:27 pm
by jgadrow
One solution is to wrap the display line in a call to substr ().

Code: Select all

echo substr ($fn->display (), 0, 250);
This will return only the first 250 characters. If there are less characters, they will all be displayed and you will have wasted a little processing power by retrieving them in this manner. However, if you check it first with strlen () you're still wasting a function call so might as well just apply substr ().