Zend - The PHP Company




Algorithms

Add Code


chopSent  

Type: code fragment
Added by: Kriek
Entered: 04/12/2003
Last modified: 05/12/2008
Rating: ** (4 votes)
Views: 3895
chopSent is very simplistic script/function intended to limit the character output of a given string and emphasize that the string does indeed continue, however input source is NOT limited, so use your imagination.


<?php 
    
/* 
    kriek at phpfreaks dot com 
    Keep this block intact please 
    */ 
    
function chopSent($varb$num) { 
        
$dNum intval($num); 
        if (
strlen($varb) > $dNum) { 
            
$nVarb substr($varb0$dNum); 
            
$nVarb .= '...'
        } 
        elseif(
strlen($varb) < $dNum) { 
            
$nVarb $varb
        } 
        return 
$nVarb
    } 
    
// Usage of function 
    
$theSent 'PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML'
    
$theSent chopSent($theSent55);   
    echo 
$theSent
?> 


Usage Example




Rate This Script





Search



This Category All Categories