Emulating grep

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattgen21
Forum Newbie
Posts: 3
Joined: Tue Sep 07, 2010 8:40 am

Emulating grep

Post by mattgen21 »

Hello! I'm new to php.

I have logs on a linux server that I'd like other admins the to have the ability to search, similar in concept to grep. Not all admins have shell access, however, so I was looking for a way implement this functionality with php since the info does reside on a web server.

Right now, the logs are being stripped of any username/passwords and other irrelevant data using grep/sed and output to a web accessible directory as simple .txt files. There isnt any sensitive data or information on the server, its just that some admins do not require shell access so they are not given it. With that in mind, which would be better to use? Pass the search strings using system() to grep or preg_grep?

Thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Emulating grep

Post by requinix »

Let grep do the work. (a) it's compiled, which your PHP will not be, and (b) it's already implemented ;)

Just remember to escape everything - "I don't need to because I trust the user" is complete bullcrap.
Post Reply