Jump to content


Photo

PHP Text Operations


  • Please log in to reply
3 replies to this topic

#1 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 15 June 2006 - 08:20 PM

Lets say i have a text file


HEADER    LIPID TRANSPORT                         23-SEP-97   1AV1              
TITLE     CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I                         
COMPND    MOL_ID: 1;           
Model           1
12345
12345
67890
67890
END
Model           2
23456
23456
17890
17890
END

Question one: how do i read the lines begining with TITLE? I need a script to ouput what comes after TITLE, In this case, I need the script to output CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I

Question two: How do i read the data between 2 lines? Lets say, if i want to read the data between Model 1 and Model 2, the script should output
12345
12345
67890
67890
END

How do i go this?
Can i do it using linux system commands?

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 15 June 2006 - 09:15 PM

Hmmm...

Kind of like asking how do I fix an engine.. are the bolts metric or US, are they left hand thread or right etc etc.

In other words, start with the structure of the file...

does each line end with the same 'character', such that said 'character' is ONLY used to end lines.

does each line represent a unqiue piece or group of information? and if it is a 'group' how are the pieces DISTINCTIVELY separated?

Will the file and subsequent versions of it follow the same format?

Those kinds of questions and answers about the file will narrow down the method of using the information in the file simply and effectively.

do a google search on php file handling read write

Lite....

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 15 June 2006 - 09:27 PM

[!--quoteo(post=384370:date=Jun 15 2006, 04:15 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ Jun 15 2006, 04:15 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hmmm...

Kind of like asking how do I fix an engine.. are the bolts metric or US, are they left hand thread or right etc etc.

In other words, start with the structure of the file...

does each line end with the same 'character', such that said 'character' is ONLY used to end lines.

does each line represent a unqiue piece or group of information? and if it is a 'group' how are the pieces DISTINCTIVELY separated?

Will the file and subsequent versions of it follow the same format?

Those kinds of questions and answers about the file will narrow down the method of using the information in the file simply and effectively.

do a google search on php file handling read write

Lite....
[/quote]

Each group of data is seperated by MODEL Number and END

Like

Model 1
1234
1234
1234 
END
Model 2
asdf
asdf
asdf
END
Model 3
uyiopityu
tryopitry
tryopiyp 
END

I cant seem to find to any code to extract just model 1,2 or 3.



#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 16 June 2006 - 01:42 AM

Look into...

strpos()

and

substr()

You can accomplish what you want with the help of those.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users