Link to home
Create AccountLog in
Avatar of BHForum
BHForum

asked on

PHP Grep command help

Just beginning with PHP. I am trying to use a PHP page to run something similar to the following Linux command:

grep "text string" filename

Open in new window


and to have it output to a web page just as the output of the grep command. Basically listing every line containing the search string.
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

As a beginner go through these string commands first http://www.w3schools.com/php/php_ref_string.asp.

There are many functions to find the occurrence of a string.. strstr,strchr,etc... the way for doing it would differ  based on the exact requirement
Avatar of BHForum
BHForum

ASKER

Thank you...will check that out
Avatar of BHForum

ASKER

Looking through these string commands, none seem to list all lines containing the string. They will find first, last, count, position, etc., but do not output showing all lines containing the string. For instance, if I had the following text file:

Line of text containing words
This is the second line of text
This line also contains words
This is the fourth line of text

Open in new window


and I search for the string "words" the result should be:

Line of text containing words
This line also contains words

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer