Revision: 70529
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 30, 2016 01:53 by a1ias
Initial Code
function summarise( $input, $break = " ", $end_text = "...", $limit = 255, $tidy_html = 1, $strip_html = 0 ) {
if ( strlen( $input ) >= $limit ) {
$breakpoint = strpos( $input, $break, $limit );
$input = substr( $input, 0, $breakpoint ) . $end_text;
}
if ( $tidy_html == 1 ) {
ob_start( );
$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 ) {
$input = strip_tags( $input );
}
return $input;
}
Initial URL
https://css-tricks.com/snippets/php/truncate-strings/
Initial Description
Shorten text while preserving the HTML tags. Useful for news and articles preview.
Initial Title
Shorten HTML text
Initial Tags
Initial Language
PHP