How to numbered line when using wordwrap to break line in long string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nhbach
    New Member
    • Dec 2009
    • 7

    How to numbered line when using wordwrap to break line in long string?

    Re: How to separate a long string to short string with space each 5 character in php?
    Thank Domilich in advanced.
    And, if i want to numbered the character in string when I use wordwap to break line this string, what I can do?

    Example:
    $str1 = "GCCGGCGGCCAGGG CGAGCGCTTGCTGGC "
    $str2 = "GCCGG CGGCC AGGGC GAGCC TTGCT GGC" (i can do that now, thanks Domilich)

    And now:
    1 GCCGG CGGCC
    11 AGGGC GAGCC
    21 TTGCT GGC

    Please help me! Thanks
    Last edited by Dormilich; Dec 10 '09, 07:13 AM. Reason: corrected my name
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    1 GCCGG CGGCC
    11 AGGGC GAGCC
    21 TTGCT GGC
    What is
    1
    11
    21 --> Is it a s-D array.? You want to put the string stripped on some delimiter and put in 2-D array.

    If not. You can use built in function explode of PHP like below.

    Code:
    $myStr = "GCCGG CGGCC AGGGC GAGCC TTGCT GGC";
    $myArray = explode(" ",$myStr);// " " Basically delimiter for stripping string to array.
    You can print the content of array.

    Code:
    print_r($myArray);
    Regards
    Dheeraj Joshi

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      the numbers are the number of the first base in that line?

      logic would tell it is: 10·n+1 (n = line number, starting from 0)

      it’s probably best to split the string every 10 bases (to get the lines) and then split each line after 5 bases.

      Comment

      • nhbach
        New Member
        • Dec 2009
        • 7

        #4
        Okay, This is my probleme:
        We have a long string (example 120 characters)
        $str1="ACATGACA TGACATGACATGACA TGACATGACATGACA TGACATGACATGACA TGACATGACATGACA TGACATGACATGACA TGACATGACATGACA TGACATGACATGACA TGACATG"

        First: I split the string every 5 bases:
        $str2="ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG ACATG"
        I can do that now. But now, we have a long line.

        And now, how can i split line after 20 bases ( 1 line have 20 base) and numbered the order at first of each line. My example: 1->21->41....


        1 ACATG ACATG ACATG ACATG
        21 ACATG ACATG ACATG ACATG
        41 ACATG ACATG ACATG ACATG
        61 ACATG ACATG ACATG ACATG
        81 ACATG ACATG ACATG ACATG
        101 ACATG ACATG ACATG ACATG

        Please give me your susgestion, thanks

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          Like Dorm said:

          Split them by line first. Then, split the lines.

          Comment

          Working...