Based loosely on the implementation of substr(), but instead of a string it's able to take the inner text of HTML/XML and truncate that instead. It's useful for trimming
There are three parameters
@param string
The input string/xml.
@param int
The length to trim.
@param string (optional)
Boundary type ['char', 'sentence', 'word']
Default 'char'
The default is to truncate the inner XML to a set character length.
$string = "<p>This is a long string</p>";
$string = subxml($string, 4);
echo $string; // Result: <p>This</p>
The other is to truncate it to a word length.
$string = "<p>This is a long string</p>";
$string = subxml($string, 2, 'word');
echo $string; // Result: <p>This is</p>
And how about to sentence length?
$string = "<p>This is a long string!! With multiple sentences.</p>";
$string = subxml($string, 1, 'sentence');
echo $string; // Result: <p>This is a long string!!</p>
- Don't trim script and style's.