By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

php - concatenate

P: 76
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.
Expand|Select|Wrap|Line Numbers
  1. if (preg_match("/DE\s+(.+)/", $buffer, $desc)) { $description .= $desc[1]; }
  2.  
thank you.
Feb 20 '08 #1
Share this Question
Share on Google+
5 Replies


stepterr
100+
P: 157
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.
Expand|Select|Wrap|Line Numbers
  1. if (preg_match("/DE\s+(.+)/", $buffer, $desc)) { $description .= $desc[1]; }
  2.  
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.
Feb 20 '08 #2

Markus
Expert 5K+
P: 6,050
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 ;)
Feb 20 '08 #3

stepterr
100+
P: 157
preg_replace() is faster ;)

markusn00b...very good point!
Feb 20 '08 #4

Markus
Expert 5K+
P: 6,050
Also, because the DE is on a new line, you might want to include the \n line carriage.
Feb 20 '08 #5

P: 76
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

Expand|Select|Wrap|Line Numbers
  1. $text_info = curl_init("http://domain.com/$id.txt");
  2. $buffer = curl_exec($text_info);
  3. echo preg_replace('/DE\s+(.+)/', ' ', $buffer);
  4.  
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.
Feb 21 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.