Trims a string to a approximate length. Sentence boundaries are preserved.
The algorythm inside calculates the sentence length to the previous and next sentences. The distance to the next sentence which is smaller will be taken to trim the string to match the approximate length parameter.
$string = "This contains two sentences. "; $string .= "Lets play around with them. ";
echo cApiStrTrimSentence($string, 40); echo cApiStrTrimSentence($string, 50);
The first example would only output the first sentence, the second example both sentences.
To match the given max length closely, the function calculates the distance to the next and previous sentences. Using the maxlength of 40 characters, the distance to the previous sentence would be 8 characters, and to the next sentence it would be 19 characters. Therefore, only the previous sentence is displayed.
The second example displays the second sentence also, since the distance to the next sentence is only 9 characters, but to the previous it is 18 characters.
If you specify the boolean flag "$hard", the limit parameter creates a hard limit instead of calculating the distance.
This function ensures that at least one sentence is returned.
Deprecated: [2015-05-21] use cString::trimSentence
Copyright: four for business AG <www.4fb.de>
Author: Timo Hummel
Located at includes/functions.api.string.php
||The string to operate on|
||The approximate number of characters|
||If true, use a hard limit for the number of characters|
||The resulting string|