Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 02-03-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  Displaying set number of words from MYSQL

I have a site that contains news articles that are added to a database.
I want to have a page that just gives a bit of a preview of the article such as maybe the first 50 words of the article, just so users can see if it is going to contain information they want to read or not.

Can anyone point me in the right direct/give and example of how to do this in PHP to display a specified number of words from a larger article in a MYSQL database. I'm hoping it is going to be a relatively simple bit of code to be honest...

Hope that all makes sence?!

Cheres
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-03-06
kungfumobiles's Avatar
Block Chopping Prices!
 
Join Date: Oct 2005
Location: Liverpool
Posts: 294
Thanks: 0
Thanked 0 Times in 0 Posts
kungfumobiles is an unknown quantity at this point
PHP Code:
<?php $s $yourVariable?>

<?php if (strlen($s) > 30) {
printf("%30.30s..."$s);
} else {
echo 
$s;
?>
I had this in an previous website, it reduced the output text to 30 characters.

Replace $yourVariable with the variable that the news articles are stored in.
__________________
AffiliStore 2 create FREE Affiliate Marketing Websites from multiple merchant product feeds.

Examples:
Cheapest Mobile Phones | New Football Kits

Last edited by kungfumobiles; 02-03-06 at 04:34 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-03-06
Paul Wright's Avatar
Fishboy
 
Join Date: Jan 2005
Location: London
Posts: 1,657
Thanks: 5
Thanked 8 Times in 4 Posts
Paul Wright is an unknown quantity at this point
Hi wardy,

I'm not renowned for my amazing php skills but i believe you're looking for is strlen() and then you can shorten the returned length to what ever value you like. The code i've been using in my projects is this...

Code:
<?php
function limit_text( $text, $limit )
{
  // figure out the total length of the string
  if( strlen($text)>$limit )
  {
    # cut the text
    $text = substr( $text,0,$limit );
    # lose any incomplete word at the end
    $text = substr( $text,0,-(strlen(strrchr($text,' '))) );
  }
  // return the processed string
  return $text;
}
?>
I like it as it deals with the words at the end of a sentence and doesn't leave your visitors hangi.....

Cheers
Paul.
__________________
Paul Wright | Affiliate Marketing Director | Mediaedge:cia
e: paul.wright@mecglobal.com | t: 0207 803 2976 | m: 07834 697 130
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-03-06
Paul Wright's Avatar
Fishboy
 
Join Date: Jan 2005
Location: London
Posts: 1,657
Thanks: 5
Thanked 8 Times in 4 Posts
Paul Wright is an unknown quantity at this point
oops, you beat me to it
__________________
Paul Wright | Affiliate Marketing Director | Mediaedge:cia
e: paul.wright@mecglobal.com | t: 0207 803 2976 | m: 07834 697 130
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 02-03-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
Nice one guys. Have had a quick go and not got it working yet but will have another go now and see if I can sort it.

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-03-06
Paul Wright's Avatar
Fishboy
 
Join Date: Jan 2005
Location: London
Posts: 1,657
Thanks: 5
Thanked 8 Times in 4 Posts
Paul Wright is an unknown quantity at this point
Found this in my bookmarks which looks like where i got it from.

http://www.desilva.biz/php/limittext.html
__________________
Paul Wright | Affiliate Marketing Director | Mediaedge:cia
e: paul.wright@mecglobal.com | t: 0207 803 2976 | m: 07834 697 130
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
British shoppers set to reject high street and rank online shopping as number one TD Nick The Affiliate Marketing Lounge 4 15-11-05 12:10 PM
Warning using reserved words in MySQL DanielCoe Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 4 21-07-05 07:32 PM
php, mysql SET for number field morleymouse Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 6 08-05-05 05:41 PM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7