/ Published in: PHP
                    
                                        
Shorten text while preserving the HTML tags. Useful for news and articles preview.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function summarise( $input, $break = " ", $end_text = "...", $limit = 255, $tidy_html = 1, $strip_html = 0 ) {
}
if ( $tidy_html == 1 ) {
$tidy = new tidy;
$config = array( 'indent' => true, 'output-xhtml' => true, 'wrap' => 200, 'clean' => true, 'show-body-only' => true );
$tidy->parseString( $input, $config, 'utf8' );
$tidy->cleanRepair( );
$input = $tidy;
}
if ( $strip_html == 1 ) {
}
return $input;
}
URL: https://css-tricks.com/snippets/php/truncate-strings/
Comments
 Subscribe to comments
                    Subscribe to comments
                
                