Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-11-2006, 05:47 PM   #1
Solid State Member
 
phpguy's Avatar
 
Join Date: Apr 2006
Posts: 13
Default PHP Script Help

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
__________________

phpguy is offline   Reply With Quote
Old 05-12-2006, 05:13 AM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: PHP Script Help

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
  }
}
?>
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 09:09 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0