Extracting specific text from a text using php

Hello guys, I am new to php and running a project. I want to extract some text i specify from a text file as in the example below:

$GPRMC,040135.000,V,190810,N*4F

I want to extract the above lines of text from among other separate text which are in the text file. The above line is just how it appears in the note pad. I think with php i can be able to do it but is hard to figure out.

I need a clue on how to go about it. Thanks in advance

Thanks for your respons. I am reading a file from a text file which is in my www directory. The text file contains raw data and I want to extract the data I want. The raw data looks like this:
07:00:57
IMEI 358998018395510
$GPRMC,040100.284,V,190810,N47
CurCell 273953 LAC 29120 Name elisa MCC 244 MNC 05 MODE 6 SSI 86
07:01:09
IMEI 358998018395510
$GPRMC,040111.000,V,190810,N
49
$GPGGA,040108.000,0,*75
CurCell 273953 LAC 29120 Name elisa MCC 244 MNC 05 MODE 6 SSI 86

And I want to separate the $GGPRMC and $GPGGA and all the the other parameters that follow on the same line. The extracted data would like this:

$GPRMC,040142,A,6009.3358,N,02444.6373,E,1.62,325,190810,
$GPRMC,040154,A,6009.3333,N,02444.6380,E,0.00,0,190810,

Hope this explanation makes sense. Many thanks.

Best Regards

Ok, so you want to be able to read a file from your server, directory, on your website, without linking it?

Try this:



<?php

/// This is the fopen()-function, which allows you to open certain files or urls. Also, "r" stands for read the file only. 

$file = fopen("notepad.txt", "r");

// Does the file even exist? If not, we give an error message.

if (file_exists($file)) {
    echo "The file $file exists and can is readable.";
} 
elseif {
    echo "The file $file does not exist, and is not be readable.";
}
else {
    echo $file;
}

?>


Assuming each line of text contains fields of data separated by commas, you can read each line of text into a text string and then use explode() to break up the line into the various data fields and then use just the data fields you need to.

Question also asked in another thread: http://www.sitepoint.com/forums/showthread.php?t=701994

Thread closed.

Thanks for your reply to my thread. To answer your question. Below is a sample of the raw data i have in a text file.

07:00:57
IMEI 358998018395510
$GPRMC,040100.284,V,190810,N47
CurCell 273953 LAC 29120 Name elisa MCC 244 MNC 05 MODE 6 SSI 86
07:01:09
IMEI 358998018395510
[COLOR=“Red”]$GPRMC,040111.000,V,190810,N
49[/COLOR]
$GPGGA,040108.000,0,*75
CurCell 273953 LAC 29120 Name elis
a MCC 244 MNC 05 MODE 6 SSI 86

I want to extract the highlited entries above .ie the ones starting with $ and all the parameters that follow. The $GPRMC must be separated from $GPGA. This is want i want and the output would look like this:

$GPRMC,040142,A,6009.3358,N,02444.6373,E,1.62,325,190810,
$GPRMC,040154,A,6009.3333,N,02444.6380,E,0.00,0,190810,

I hope my explanation is understandable. Many thanks

In order for someone to help you it is best to post a sample of the problem, which in you case means 1 or more lines which you do not want to catch, along with a 1 or more lines you do want to filter out.

Then tell us the rule which has to be applied, or show exactly the result you want.

Create an explicit “before” and “after”.