473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

php - concatenate

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
5 2524
stepterr
157 100+
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
6,050 Expert 4TB
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
157 100+
preg_replace() is faster ;)

markusn00b...very good point!
Feb 20 '08 #4
Markus
6,050 Expert 4TB
Also, because the DE is on a new line, you might want to include the \n line carriage.
Feb 20 '08 #5
idorjee
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

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

Similar topics

0
by: Nick Heppleston | last post by:
I have a concatenation problem and I was wondering if somebody might be able to offer some help :-) I have the following table structure holding product long descriptions: Part...
30
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
8
by: Dixie | last post by:
I have the results of a query to send to a mailmerge with Word 2000. The query produces say 6 to 8 records, where only 1 of the fields is different from record to record. I can only have one...
6
by: Sheldon | last post by:
Hi, I am trying to build a large array using concatenate function in python. So as I loop over the number of arrays, of which there are 12 (4 down and 3 across), I create 3 long arrays by...
14
by: metamorphiq | last post by:
Hello, I'm a Java programmer, so I'm probably asking a very simple question here, but I have trouble solving it :) I'd like to know how you concatenate multiple (4, in my case) char* in C++,...
2
by: exapplerep | last post by:
I've seen how to use VBA code to concatenate two fields into a third by using an expression in the "After Update" property in fields 1 & 2. field3 = field1 + field2 The above code would go...
4
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
12
by: parth | last post by:
Hi I want to achieve the following transformation of data using a stored procedure. Source col1 col2(varchar) -------------------------
13
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that...
10
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.