|
@@ 133-144 (lines=12) @@
|
| 130 |
|
|
| 131 |
|
// add each sentence while there are enough words to do so |
| 132 |
|
$result = ''; |
| 133 |
|
do { |
| 134 |
|
$result .= trim(array_shift( $sentences )).'.'; |
| 135 |
|
if(count($sentences) > 0) { |
| 136 |
|
$count += count(explode(' ', $sentences[0])); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
// Ensure that we don't trim half way through a tag or a link |
| 140 |
|
$brokenLink = ( |
| 141 |
|
substr_count($result,'<') != substr_count($result,'>')) || |
| 142 |
|
(substr_count($result,'<a') != substr_count($result,'</a') |
| 143 |
|
); |
| 144 |
|
} while(($count < $maxWords || $brokenLink) && $sentences && trim( $sentences[0])); |
| 145 |
|
|
| 146 |
|
if(preg_match('/<a[^>]*>/', $result) && !preg_match( '/<\/a>/', $result)) $result .= '</a>'; |
| 147 |
|
|
|
@@ 173-185 (lines=13) @@
|
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
// add each sentence while there are enough words to do so |
| 173 |
|
do { |
| 174 |
|
$result .= trim(array_shift($sentences)); |
| 175 |
|
if($sentences) { |
| 176 |
|
$result .= '. '; |
| 177 |
|
$count += count(explode(' ', $sentences[0])); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
// Ensure that we don't trim half way through a tag or a link |
| 181 |
|
$brokenLink = ( |
| 182 |
|
substr_count($result,'<') != substr_count($result,'>')) || |
| 183 |
|
(substr_count($result,'<a') != substr_count($result,'</a') |
| 184 |
|
); |
| 185 |
|
} while(($count < $maxWords || $brokenLink) && $sentences && trim($sentences[0])); |
| 186 |
|
|
| 187 |
|
if(preg_match( '/<a[^>]*>/', $result) && !preg_match( '/<\/a>/', $result)) { |
| 188 |
|
$result .= '</a>'; |