views:

107

answers:

3

I have here a multiple data, I want to search a name and date, if I typed JULIUS CESAR as name then the whole data about JULIUS will be extracted.? What if i want only to extract information? This file was save in texteditor(linux).

#

Record number: 1 Date: 08-Oct-08 Time: 23:45:01 Name: JULIUS CESAR Address: BAGUIO CITY, Philippines Information: I lived in Peza Loakan, Bagiou City A Computer Engineering student An OJT at TIPI. 23 years old.

Record number: 2 Date: 09-Oct-08 Time: 23:45:01 Name: JOHN Castro Address: BAGUIO CITY, Philippines Information: I lived in Peza Loakan, Bagiou City A Electronics Comm. Engineering Student at SLU. An OJT at TIPI. My Hobby is Programming.

Record number: 3 Date: 08-Oct-08 Time: 23:45:01 Name: CESAR JOSE Address: BAGUIO CITY, Philippines Information: Hi,, I lived Manila City A Computer Engineering student Working at TIPI.

#
A: 

Does this question really have anything to do with SQL?

Cade Roux
I've retagged it to remove the SQL tag.
Cade Roux
+2  A: 

If it is one line per entry, you could use a regular expression such as:

$name = "JULIUS CESAR";

Then use:

/$name/i

to test if each line is about "JULIUS CESAR." Then you simply have to use the following regex to extract the information (once you find the line):

/Record number: (\d+) Date: (\d+)-(\w+)-(\d+) Time: (\d+):(\d+):(\d+) Name: $name Address: ([\w\s]+), ([\w\s]+?) Information: (.+?)$/i

$1 = record number

$2-$4 = date

$5-$7 = time

$6 = address

$7 = comments

I would write a code example, but my perl is rusty. I hope this helps :)

nlaq
A: 

In PHP, you can run a SQL select statement like:

"SELECT * WHERE name LIKE 'JULIUS%';"

There are native aspects of PHP where you can get all of your results in an associative array. I'm pretty sure it's ordered by row order. Then you can just do something like this:

echo implode(" ", $whole_row);

Hope this is what you're looking for!

Robert Elwell