Browse Source

Fixed issue #34: "HTML entities can be cut in half when truncating posts"

pull/40/head
Michael Save 12 years ago
parent
commit
ae76ddb079
  1. 8
      inc/display.php

8
inc/display.php

@ -156,6 +156,7 @@
function truncate($body, $url, $max_lines = false, $max_chars = false) { function truncate($body, $url, $max_lines = false, $max_chars = false) {
global $config; global $config;
if($max_lines === false) if($max_lines === false)
$max_lines = $config['body_truncate']; $max_lines = $config['body_truncate'];
if($max_chars === false) if($max_chars === false)
@ -192,11 +193,18 @@
} }
} }
// remove broken HTML entity at the end (if existent)
$body = preg_replace('/&[^;]+$/', '', $body);
// Close any open tags // Close any open tags
foreach($tags as &$tag) { foreach($tags as &$tag) {
$body .= "</{$tag}>"; $body .= "</{$tag}>";
} }
} else {
// remove broken HTML entity at the end (if existent)
$body = preg_replace('/&[^;]+$/', '', $body);
} }
$body .= '<span class="toolong">Post too long. Click <a href="' . $url . '">here</a> to view the full text.</span>'; $body .= '<span class="toolong">Post too long. Click <a href="' . $url . '">here</a> to view the full text.</span>';
} }

Loading…
Cancel
Save