php - concatenate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idorjee
    New Member
    • Mar 2007
    • 76

    php - concatenate

    hi,
    how can i concatenate the part of the first and the next line, leaving the 'DE' in the beginning if i have the following in a text file?

    DE Chloride intracellular channel protein 5 (Chlorine channel protein
    DE p64).

    i want it like this:
    Chloride intracellular channel protein 5 (Chlorine channel protein p64).

    the following doesn't work.
    Code:
    if (preg_match("/DE\s+(.+)/", $buffer, $desc)) { $description .= $desc[1]; }
    thank you.
  • stepterr
    New Member
    • Nov 2007
    • 157

    #2
    Originally posted by idorjee
    hi,
    how can i concatenate the part of the first and the next line, leaving the 'DE' in the beginning if i have the following in a text file?

    DE Chloride intracellular channel protein 5 (Chlorine channel protein
    DE p64).

    i want it like this:
    Chloride intracellular channel protein 5 (Chlorine channel protein p64).

    the following doesn't work.
    Code:
    if (preg_match("/DE\s+(.+)/", $buffer, $desc)) { $description .= $desc[1]; }
    thank you.
    idorjee,
    preg_match() just returns the number of times a specified pattern is matched. Take a look at the str_replace () or the substr_replace( ) functions. Reading the line in as a string and then using one of those you could replace "DE" with "" to get your desired result.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by stepterr
      idorjee,
      preg_match() just returns the number of times a specified pattern is matched. Take a look at the str_replace () or the substr_replace( ) functions. Reading the line in as a string and then using one of those you could replace "DE" with "" to get your desired result.
      preg_replace() is faster ;)

      Comment

      • stepterr
        New Member
        • Nov 2007
        • 157

        #4
        Originally posted by markusn00b
        preg_replace() is faster ;)

        markusn00b...ve ry good point!

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Also, because the DE is on a new line, you might want to include the \n line carriage.

          Comment

          • idorjee
            New Member
            • Mar 2007
            • 76

            #6
            hi guys,
            thanks for your suggestions, but i still couldn't get around with it. following is a part of the script that i'm working on

            Code:
            $text_info = curl_init("http://domain.com/$id.txt");
            $buffer = curl_exec($text_info);
            echo preg_replace('/DE\s+(.+)/', ' ', $buffer);
            i was wondering why do i need to replace my pattern with a space, as that's the one i need. and also the are in the $buffer, lines like:

            DE Potassium voltage-gated channel subfamily A member 3 (Voltage-gated
            DE potassium channel subunit Kv1.3) (HPCN3) (HGK5) (HuKIII) (HLK3).
            RP NUCLEOTIDE SEQUENCE [GENOMIC DNA].

            the last line also has the 'DE\s+(.+)' pattern which i am not interested in.

            is there any way i could save the replaced part? how could i do this. please help.
            thanks a lot.

            Comment

            Working...