I have a string that if it is longer than lets say 10 words, I want to split it into two parts. The second part will be included else-where after a ‘more’ link.
The string will hold html tags too though.
For an example the string could be:
<p>This is just a test string with more words than the <strong>amount allow</strong> before split, blah blah blah</p>
So in the case I would want:
$string[0] // <p>This is just a test string with more words than</p>;
$string[1] // <p>the <strong>amount allow</strong> before split, blah blah blah</p>;
Thanks in advance
Well, I’ve had the same issues. I solved this in letting my news-writers allow to use “[intro]…[/intro]”-Tags within their texts. Then I parsed the tags with a regex.
If the cutting should be done automatically without using special tags, it’s a bit more difficult. You could use the
substr()-function. But then you would have problems with the html-tags. Therefore I would cut them as well with something like:substr(strip_tags($text), 0, 50). This would allow 50 chars to be displayed, exclusive the html-tags.Maybe this can help you 🙂