Split text into two columns

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim

    Split text into two columns

    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


  • Nikolai Chuvakhin

    #2
    Re: Split text into two columns

    "Tim" <tjccowan@hotma il.com> wrote
    in message news:<lwlSa.963 6$104.1068452@n ews20.bellgloba l.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

    Comment

    • P'tit Marcel

      #3
      Re: Split text into two columns

      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

      Comment

      Working...