PHP Script Help

phpguy1

Solid State Member
Messages
13
I need help doing the following thing;

Say i have a file called users.txt and in this file is the following information

Name: John Smith
Address: 10 King Street
Phone: 01612763999

Name: Joe King
Address: 22 Long Street
Phone: 01612763988

I then want another script which reads this file and extracts all the names and "echo"s them.

Does anyone know how i would be able to do this using PHP.

Thanks
 
Code:
<?php
$url = "users.txt";
$file = file($url); //open file for reading
for ($line=0;$line<=sizeof($file);$line++) //look at lines, one at a time from zero to the end of the file
{
  if (ereg("Name:", $file[$line])) //look for the regular expression Name:
  {
    $temp = split(":", $file[$line]); //split the line on a common charector (:)
    print "name = $temp[1]<br>"; //print the sceond part of the split array as this is the name
  }
}
?>
 
Back
Top Bottom