364,088 Members | 5545 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Split text into two columns

Tim
P: n/a
Tim
Hi

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!

My next idea was to strip the HTML tags from the text and then split it up
and then reapply the HTML tags, but I am not sure this would work either.

Has anyone come across this problem and do you have a solution or know of
one? I would really appreciate it.

Thanks

Tim


Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


Nikolai Chuvakhin
P: n/a
Nikolai Chuvakhin
"Tim" <tjccowan@hotmail.com> wrote
in message news:<lwlSa.9636$104.1068452@news20.bellglobal.com >...[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.[/color]

First of all, understand that you will NOT be able to do this
as precisely as you would on a printed page. In particular,
there is no way to enforce smooth transition from one column
to another in the middle of a sentence.
[color=blue]
> 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]

How about finding the <p>, <h?>, or <?l> tag most closely following
the middle character?

Cheers,
NC
Jul 16 '05 #2

P'tit Marcel
P: n/a
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
Jul 16 '05 #3

Post your reply

Help answer this question



Didn't find the answer to your PHP question?

You can also browse similar questions: PHP