I am currently studying the separation of a very long string, which may contain HTML characteristics.
Example:
Thiiiissssaaaveryyyylonnngggstringgg
For this, I used this function in the past:
function split($sString, $iCount = 75) { $text = $sString; $new_text = ''; $text_1 = explode('>',$text); $sizeof = sizeof($text_1); for ($i=0; $i<$sizeof; ++$i) { $text_2 = explode('<',$text_1[$i]); if (!empty($text_2[0])) { $new_text .= preg_replace('#([^\n\r .]{'. $iCount .'})#iu', '\\1 ', $text_2[0]); } if (!empty($text_2[1])) { $new_text .= '<' . $text_2[1] . '>'; } } return $new_text; }
The function works to pick up such characters and break them after X characters. The problem is that HTML or ASCII characters are mixed there as follows:
Thissssiisss<a href="#">lonnnggg</a>stingäää
I tried to figure out how to break this line above and not count the characters in the HTML tags and count each ASCII character as 1.
Any help would be great.
thanks
source share