How to split a string by number of chars ?

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

    How to split a string by number of chars ?

    This has been done before but not sure how:

    Say I have a string of 1000 chars. I want to split the string into two
    variables (two array element variables would be OK) one has 200 chars
    the other has 800 chars. How would I do this? Must be simple in PHP...
  • Andy Hassall

    #2
    Re: How to split a string by number of chars ?

    On Sun, 07 Nov 2004 19:39:28 GMT, leegold2 <leegold@nospam .net> wrote:
    [color=blue]
    >This has been done before but not sure how:
    >
    >Say I have a string of 1000 chars. I want to split the string into two
    >variables (two array element variables would be OK) one has 200 chars
    >the other has 800 chars. How would I do this? Must be simple in PHP...[/color]

    substr

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • leegold2

      #3
      Re: How to split a string by number of chars ?

      Andy Hassall wrote:[color=blue]
      > On Sun, 07 Nov 2004 19:39:28 GMT, leegold2 <leegold@nospam .net> wrote:
      >
      >[color=green]
      >>This has been done before but not sure how:
      >>
      >>Say I have a string of 1000 chars. I want to split the string into two
      >>variables (two array element variables would be OK) one has 200 chars
      >>the other has 800 chars. How would I do this? Must be simple in PHP...[/color]
      >
      >
      > substr
      >[/color]
      Like:
      $d_content1 = substr($d_conte nt,0,100);
      $d_content2 = substr($d_conte nt,100);

      But, I need it to break the string on the nearest word. I jusr realized
      that because I got:

      $d_content1 == ....this is really gre
      $d_content2 == at

      I need it to do:

      $d_content1 == ....this is really
      $d_content2 == great

      Thanks,
      Lee G.

      Comment

      • Michael Fesser

        #4
        Re: How to split a string by number of chars ?

        .oO(leegold2)
        [color=blue]
        >But, I need it to break the string on the nearest word.[/color]



        Micha

        Comment

        Working...