Wednesday, 3 June 2015

get a subset of words

<?php 
 function get_words($string$max$offset 0$append_dots true){ 
    
$words explode(" "$string); 
    return 
        (
$append_dots && $offset " ... " "") .  
        
implode(" "array_splice($words$offset$max)) .  
        (
$append_dots && $max count($words) ? " ... " ""); 
}

?>
functions.php
<?php 

$test_string 
"This is a basic test string to test words." echo get_words($test_string5); // prints: This is a basic test ... echo get_words($test_string50false); // prints: This is a basic test


?> 

0 comments:

Post a Comment