PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] How do i limit characters echoed from database?

 July 26, 2022     character, dreamweaver, limit, mysql, php     No comments   

Issue

I've made a "news" section on my website, and I'm trying to make a little box on my template to the right which echos latest news (title, text and author). My problem is that I only wish to echo about 20 characters from "text" in the little box.

I'm using dreamweaver, and i'm horrible at php. Here's the code. It's the "tekst" field i wan't to limit to 20 characters.

<?php do { ?>
<h1><?php echo $row_posts['tittel']; ?></h1>
<p class="posttekst">&nbsp;<?php echo $row_posts['tekst']; ?></p>
<p><em><?php echo $row_posts['forfatter']; ?> <?php echo $row_posts['dato']; ?></em></p>
<hr />
<?php } while ($row_posts = mysql_fetch_assoc($posts)); ?>

It's in norwegian - tittel : title, tekst: text, forfatter: author, dato:date.

Thanks for any help.


Solution

PHP's substr() is what you're looking for: http://www.php.net/manual/en/function.substr.php

<?php echo substr($row_posts['tekst'], 0, 20); ?>



Answered By - davey
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing