0

Hi All,
Very new to web design and PHP, but I seem to be learning along the way.
I am building a HGV Drivers website for a friend of mine for his business. On the homepage I have managed to echo text for my 'Latest News' section. I would like to be able to limit the text to say about 60 characters. Does anyone know how I would be able to do this? Need a simple speaking solution lol.

This is the php code for my Latest News Section;

   <?php do { ?>
      <div id="newsRepeatRegion">
        <div class="newsRepeatRegionHeadline"><?php echo $row_newsRS['news.headline']; ?></div>
        <div class="newsRepeatRegionNews"><?php echo $row_newsRS['new.description'];
?>
</div>
        <div class="newsRepeatRegionDate"><?php echo date("d F Y",strtotime($row_newsRS['news.date'])); ?></div>
  <div class="newsRepeatRegionLink"><a href="news.php?id=<?php echo $row_newsRS['id']; ?>">Read More</a></div>
      </div>
      <?php } while ($row_newsRS = mysql_fetch_assoc($newsRS)); ?>

Hope someone can help!

Cheers
Kieron

Edited by diafol: applied code tags

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by MarPlo
0

Hi,

The substr() function can be used to extract a portion of a string, with a specified length.
Here is an example:

$str = 'Here can be a long text, we keep only the first 25 characters';
$str = substr($str, 0, 25);
echo $str;         // Here can be a long text,

In your code will be:echo substr($row_newsRS['id'], 0, 60);
More details an examples with substr() you can find on php.net .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.