Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
help to implement code ...
Old 07-26-2010, 09:04 PM help to implement code ...
Novice Talker

Posts: 14
Trades: 0
Hi!

I got a shortcode (code that can be called elsewhere on the page) om my webpage that looks like this:

PHP Code:
SC_BEGIN NEWSBODY2
global $tp;
$news_item getcachedvars('current_news_item');
$news_body $tp -> toHTML($news_item['news_body']);
return 
$news_body;
SC_END 
This calls a text from the mysql.

But I want to edit this code so if the text is more than say 3 words long it will return with three dots like this:

Quote:
Word1 word2 word3 …
I found a code that could achieve this:

PHP Code:
$threshold_length 3// 3 words max
$phrase 'word1 word2 word3 word4'// populate this with the text you want to display
$abody str_word_count($phrase,2);
if(
count($abody) >= $threshold_length){ // gotta cut
  
$tbody array_keys($abody);
  echo 
'' substr($phrase,0,$tbody[$threshold_length]) . '... ';
} else { 
// put the whole thing
  
echo ' . $phrase . ';

I tried to implement this code into the shortcode above but cant succed. But Im not very good in coding.

Any help with solution would be very much apreciated.

So that the code just calls say the first three words in the mysql

Thanks!

/ P

Last edited by perik; 07-26-2010 at 09:07 PM..
perik is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-27-2010, 08:35 AM Re: help to implement code ...
Average Talker

Posts: 16
Name: Filip Filipov
Location: Bulgaria
Trades: 0
Try this:

PHP Code:
$threshold_length 3// 3 words max
$phrase 'word1 word2 word3 word4'// populate this with the text you want to display
$words explode(' '$phrase);
if ( 
count($words) > $threshold_length ) {
  
$phrase $words[0] . ' ' $words[1] . ' ' $words[2] . ' ...';
}
echo 
$phrase
__________________

Please login or register to view this content. Registration is FREE
- IP Address Lookup. Domain Lookup. Geolocation by IP or Doomain Name

Please login or register to view this content. Registration is FREE
- Check PageRank, Alexa Rank, Backlinks, Indexed Pages, ...
primecode is offline
Reply With Quote
View Public Profile Visit primecode's homepage!
 
Reply     « Reply to help to implement code ...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28257 seconds with 12 queries