How to seperate data from line in txt file

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
meannate
New php-forum User
New php-forum User
Posts: 8
Joined: Mon Nov 04, 2002 12:06 pm
Location: West Los Angeles
Contact:

Thu Jan 16, 2003 2:50 pm

I would imagine the data in your datafile is separated by a colon, coma, or maybe a space... you say your interested only in the last item.

Code: Select all

$datafilename = "datafile.log";
$datafile = fopen($datafilename, "r") or die("Couldn't Open");
$data = fread($datafile, filesize($datafilename) or die ("Couldn't Read");
fclose($datafile);

$data = split("\r", $data);

foreach ($data as $dataline) {
  //STRRCHR SEARCHES FOR LAST OCCURANCE OF ':' AND RETURNS THE REST OF THE STRING
  $THIS = strrchr($dataline, ":");

  echo $THIS;
}


-Nathan

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests