what function will split text

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

    what function will split text

    Hi,
    I need a function that will divide text from mysql in 2 parts, so that I
    can display first half in one column and second half in second column.
    I can't find what function will do this job.
    Here is part of what I have.

    $myrow = mysql_fetch_ass oc($rsindexpage );
    //function wordcount
    $wc = str_word_count( $myrow);
    $half = ($wc/2);
    //function divide text in two columns
    <tr>
    <td width="150" valign="top">
    <?php
    $str = $myrow;
    $split = NEED_FUNCTION_H ERE($str, $half);
    $first = $split[0];
    $second = $split[1];
    echo "$first";
    ?>
    </td>
    <td width="150" valign="top">
    <?php
    echo "$second";
    ?>
    </td>
    </tr>


  • Jerry Gitomer

    #2
    Re: what function will split text

    ashok wrote:
    Hi,
    I need a function that will divide text from mysql in 2 parts, so that I
    can display first half in one column and second half in second column.
    I can't find what function will do this job.
    Here is part of what I have.
    >
    $myrow = mysql_fetch_ass oc($rsindexpage );
    //function wordcount
    $wc = str_word_count( $myrow);
    $half = ($wc/2);
    //function divide text in two columns
    <tr>
    <td width="150" valign="top">
    <?php
    $str = $myrow;
    $split = NEED_FUNCTION_H ERE($str, $half);
    $first = $split[0];
    $second = $split[1];
    echo "$first";
    ?>
    </td>
    <td width="150" valign="top">
    <?php
    echo "$second";
    ?>
    </td>
    </tr>
    >
    >
    Look at the substr function. The syntax is:

    substr(<string name>, <start position>, <length>)

    so, assuming a string of length 150 that you
    want to split into two equal parts:

    $first = substr($str, 0, 75);
    $second = substr($str, 75, 75);

    HTH

    Jerry

    Comment

    • mootmail-googlegroups@yahoo.com

      #3
      Re: what function will split text

      ashok wrote:
      Hi,
      I need a function that will divide text from mysql in 2 parts, so that I
      can display first half in one column and second half in second column.
      I can't find what function will do this job.
      Here is part of what I have.
      >
      $myrow = mysql_fetch_ass oc($rsindexpage );
      //function wordcount
      $wc = str_word_count( $myrow);
      $half = ($wc/2);
      //function divide text in two columns
      <tr>
      <td width="150" valign="top">
      <?php
      $str = $myrow;
      $split = NEED_FUNCTION_H ERE($str, $half);
      $first = $split[0];
      $second = $split[1];
      echo "$first";
      ?>
      </td>
      <td width="150" valign="top">
      <?php
      echo "$second";
      ?>
      </td>
      </tr>

      Is this text a fixed-length, or is there a delimiter of some kind?

      If there is a delimiter, consider explode:


      Comment

      • Klaus Brune

        #4
        Re: what function will split text

        In article <efmieh$1fj2$1@ news.mtu.ru>, ashok@replyhere .com says...
        Hi,
        I need a function that will divide text from mysql in 2 parts, so that I
        can display first half in one column and second half in second column.
        I can't find what function will do this job.
        It may or may not be overkill, depending on the complexity of the
        delimiter and your split, but my first thought went to using preg_match
        and assigning the $matches array. Then use sub-expressions (parenthesis)
        to extract the parts you need. I use this all the time to, say, batch-
        convert a a bunch of web pages for inclusion in a database, with header
        field like metatag keywords and description extracted nicely.

        Just give a shout here if you'd like to see some sample code, and I'll
        see if I can hunt it down.

        Later
        GC

        Comment

        Working...