Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2005, 07:32 AM   PM User | #1
Yaggles
Regular Coder

 
Join Date: Jan 2005
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
Yaggles is an unknown quantity at this point
Dotting function

This function takes text and, after a certain number of characters have been shown, it replaces the remaining text with " ...". It is easily customizable.

If you didn't understand what I just said, here's the function's code and an example:
PHP Code:
function preView($variable$maxchars)
{
    
$dnum intval($maxchars);
    if(
strlen($variable) > $dnum)
    {
        
$splitpnt strpos($variable," ",$dnum);
        
$var substr($variable0$splitpnt);
        
$var .= " ...";
    }
    elseif(
strlen($variable) < $dnum)
    {
        
$var $variable;
    }
    return 
$var;

Example and Output:
PHP Code:
$variable 'This is so cool!';
$new_variable preView($variable5); 
That would output 'This ...' (quotes excluded) because it goes five characters before it dots the rest.

Disclaimer: I found this script somewhere else, renamed the function, and some of the variables names are changed.
Yaggles is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 07:43 PM.


Advertisement
Log in to turn off these ads.