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
https://forums.phpfreaks.com/topic/57265-solved-article-taster/
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
https://forums.phpfreaks.com/topic/57265-solved-article-taster/#findComment-283052
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
https://forums.phpfreaks.com/topic/57265-solved-article-taster/#findComment-283087
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.