FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to extract this?





kk_loke86
I need to extract the text below.

SIGNAL 1 19 Potential.
CHAIN 20 873 104 kDa microneme/rhoptry antigen.
/FTId=PRO_0000232680.
PROPEP 874 893 Removed in mature form (Potential).
/FTId=PRO_0000232681.
COMPBIAS 215 220 Poly-Leu.
COMPBIAS 486 683 Lys-rich.
COMPBIAS 854 859 Poly-Arg.
LIPID 873 873 GPI-anchor amidated aspartate
(Potential).

I want to extract the two numbers separated by a space into two valuables $start and $end.
The CAPITAL letter term is stored in another variable $strand.

example after extraction for the first line.
$strand=SIGNAL;
$start=1;
$end=19;
$text=Potential.

for line two, the $text should like this
104 kDa microneme/rhoptry antigen. /FTId=PRO_0000232680. (joint with the next line).

I have tried to extract the numbers with regex /[0-9]+ [0-9]+/ after trim each line. But it doesn`t work. (Actually I intend to obtain the number in the format like this $num=1 19 [line 1]). Don`t know why? Is my regex wrong?
sonam
First of all we need more information. Are this data stored in some data base (txt, MySql) or it is just one string. If you are using some data base then we can read datas in few different way. If datas only one string then we must use str functions.

Sonam
kv
Assuming you are processing one line at a time, here is code to split one line.

Code:

//assume $line contains one line of data

$arr=explode(" ", $line, 4);

$strand=$arr[0];
$start=$arr[1];
$end=$arr[2];
$text=$arr[3];



If the data is in a file, all you need to do is read lines inside a loop (one line at a time) and use the code inside the loop.
sonam
Another version for same result like kv scrip:
Code:
list($strand, $start, $end, $text)  = explode(" ", $line, 4);

Sonam
kk_loke86
May I know what is the 4 in the explode function means? Because it is what I didn`t put into my coding to extract each line.
kv
kk_loke86 wrote:
May I know what is the 4 in the explode function means? Because it is what I didn`t put into my coding to extract each line.


It just means limit the number of extracted data to 4. For example, if you take this line

CHAIN 20 873 104 kDa microneme/rhoptry antigen.

and explode, it will be tokenized into 7 parts. But you don't need 7 parts. All you need is take first three parts and consider rest of the line as fourth part. If you pass the third parameter as 4, it does exactly this.
manav
str pos and substr combo will do it if u r not willin to write a reguler expression
Related topics
change the WHM skeleton
Can't extract a file from a Zip archive!!!
Extract Zips/rars?
extract zip/rar in DA.
Can't extract this file
Zip Extract Question
Extract fonts from PDF files
Can't Extract , Can't Install
youtube videos
Software to extract frames from a DVD.
How can I extract .tar.gz backup files?
Extract info from a webpage
upload .gz file via ftp and extract remotely
Extract a paragraph or specified character/word from mysql
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.