Jump to content

[SOLVED] Article "taster"


conker87

Recommended Posts

I have a site with articles, reviews etc. I have the following code to list the articles:

 

<?php
$query = "SELECT * FROM " ARTICLE_TBL;
$result = mysql_query($query);
$rowcount = mysql_num_rows($result);
echo "Listing $rowcount results.<ul>";
while ($article = mysql_fetch_array($result))
  {
?>
<li><a href="/i-article:<?=$article['id']; ?>"><b><?=$article['title']; ?></b></a> by <i><?=$article['author']; ?></i>.</li>
<?
  }
  echo "</ul>";
?>

Any articles found will be displayed in a bullet list. This is great, but I'm wanting to show a little example of what the start of the article looks like, say about 50-100 chars? I think rtrim() but that only trims away specific characters from the end.

 

Any ideas?

Link to comment
Share on other sites

Well, not too shure about this but u could make a textBox with 0 border and limit the textbox to 50 or 100 chars.

put your result in a variable like this:

 

$article_body=mysql_numrows($result);

then put the initial value in the text box as "<?php echo $article; ?>";

That should do the trick ;)

Link to comment
Share on other sites

This code should work for you:

$article_body = substr(strip_tags(VARIABLE WHERE INFO IS STORED), '0', '100');

strip tags will remove any html code, because it can give out very bad results if you cut off halfway through a tag, such as a link.

The 100 is how many characters to show, just change it to what you need.

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.