conker87 Posted June 26, 2007 Share Posted June 26, 2007 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? Quote Link to comment Share on other sites More sharing options...
bigbob Posted June 26, 2007 Share Posted June 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
conker87 Posted June 26, 2007 Author Share Posted June 26, 2007 Hmm. That would work. I'd rather not have it in a text box really. Just looks really there. Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 26, 2007 Share Posted June 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
conker87 Posted June 26, 2007 Author Share Posted June 26, 2007 Yeah, I had a look around the PHP site looking for any functions to use, came across those and made a little function a little different to that. Though yours is a little smaller, so I'll use that. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.