CanMan2004 Posted June 28, 2006 Share Posted June 28, 2006 Hi allI have a site which creates a log txt file for me, inside it, it stores the name of the person who logged in and there age, for example the txt file might look likeusername - Dave Smithage - 34How can I get php to open the file and read the username piece of information inside the txt file and ignore the rest? I have read some information on reading files but all my examples seem to fail.Any help would be greatThanks in advanceDave Link to comment https://forums.phpfreaks.com/topic/13107-php-reading-a-txt-file/ Share on other sites More sharing options...
alexruimy Posted June 28, 2006 Share Posted June 28, 2006 Assuming the exact contents of your log.txt file are[code]username - Dave Smithage - 34[/code]Try this:[code]<?$file = "log.txt";$size = filesize($file);$fh = fopen ($file, 'r');$data = fread ($fh, $size);fclose($fh);$lines = explode("\n",$data);$pieces = explode(" - ",$lines[0]);$username = $pieces[1];echo $username;?>[/code] Link to comment https://forums.phpfreaks.com/topic/13107-php-reading-a-txt-file/#findComment-50395 Share on other sites More sharing options...
CanMan2004 Posted June 28, 2006 Author Share Posted June 28, 2006 You're a star, thank you Link to comment https://forums.phpfreaks.com/topic/13107-php-reading-a-txt-file/#findComment-50407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.