How to cut a string in PHP, leaving only the first 1000 characters? In this case, the line contains HTML tags and you need to trim the line without taking into account the tags. (i.e., just substr, does not fit) Ie 1000 characters should stay text, and how many characters HTML will occupy is not important ...
1 answer
There are several ways
Revise the task, cut out all html and trim
$ test = strip_tags ($ test); $ test = substr ($ test, 0,1000);
Enter a description tag, let's say
<cat>
or bb-code and trim[cat]
.- Cut not by characters but by the number of words, for example, with the condition that the tag be necessarily closed after.
Only the method with the number 1,2-in will suit you, if you cut it with a machine, then with a probability of 98% you will cut off the closing tags and fix bugs for life.
|