ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
On my local linux machine I have a extracted with a perl script from the /etc/passwd file a list of usernames. In php I want to display all usernames, and later on manipulate them. Some example data:
I would avoid the use of file() because it is a slow function, instead use fopen() or
file_get_contents().
If all you want is the usernames from the /etc/passwd file, you could do :
Okey! This worked for me. I used the print and echo functions at the end of the screen to see if it works and yes! I'm now getting a nice filtered list.. My last problem:
Now I have a list with all the users I want to combine it together with the command below. For each user I want to see the results of 'netstat -ea | grep user'.
... ... // find if a string contain an userfrom the list, if yes return its position function find_user($list, $string) { $i = 0; foreach($list as $user) { if(strriipos($string, $user) > 0) { return $i; } $i++; } return false; }
// Array where all relevant netstat lines will be stored, its key will be // the user name $users_net = Array();
// open a pipe so you can easilly read line by line $netstat = popen("netstat -an", "r");
if(!$netstat) { echo "could not open netstat"); exit; }
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.