P'tit Marcel
Tim écrivit:
[color=blue]
> I want to be able to split the contents of a text field into two or
> maybe three columns. The text field contains text AND HTML mark-up.
>
> My initial thought was to find the middle character and then go to the
> nearest space and split the text that way, but it sometimes splits in
> the middle of an HTML tag: not pretty![/color]
function split_pos($text) {
/* find middle space in text */
$mid = (int) strlen($text)/2 - 1;
$cut = strpos($text , ' ' , $mid);
$part1= substr($text , 0 , $cut + 1);
$pos1 = strrpos($part1 , '<');
$pos2 = strrpos($part1 , '>');
if (($pos1 < $pos2) or ($pos1 === False))
return $cut; */ no html tag around */
$pos3 = strpos($text , '>' , $cut1 + 1);
if($pos3 !== False)
return $pos3; */ end of middle html tag */
else return $cut; */ unbalancing < > */
}
not tested
hth
--
P'tit Marcel |