Jeroen1000 Posted September 28, 2009 Share Posted September 28, 2009 Hi everyone, I've made a .txt file with a predefined format. For example: 192.168.0.1:Bob:/home/Bob 192.168.0.2:Joe:/home/Joe I found how to get a user's IP address when he/she visites the php page, but now I to read the correct line of that text file into an array. When Bob visites I would need to build some array like $Array[0]= 192.168.0.1 $Array[1]= Bob $Array[2]=/home/Bob Can anyone offer advise on how to accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/175775-solved-extract-a-specific-line-from-a-text-file/ Share on other sites More sharing options...
Zane Posted September 28, 2009 Share Posted September 28, 2009 $yourfile = "thelog.txt"; foreach(file($yourfile) as $x) $data[] = explode(':', $x); echo "" , print_r($data), ""; Quote Link to comment https://forums.phpfreaks.com/topic/175775-solved-extract-a-specific-line-from-a-text-file/#findComment-926267 Share on other sites More sharing options...
Jeroen1000 Posted September 28, 2009 Author Share Posted September 28, 2009 Thank you very much. Another useful trick learned Quote Link to comment https://forums.phpfreaks.com/topic/175775-solved-extract-a-specific-line-from-a-text-file/#findComment-926350 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.