Hello,
I am currently looking into spliting a very long string that could contain HTML characteristics.
Once example is:
Thiiiissssaaaveryyyylonnngggstringgg
For this I have 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 split them after X characters. The problem is when HTML or ASCII characters are mixed in there like this:
Thissssiisss<a href="#">lonnnggg</a>stingäää
I have been trying to figure out how to split this string above and to not count characters within HTML tags and to count each ASCII character as 1.
Any help would be great.
Thank you