0

I am using PHP to execute a command using exec() which works fine.

example:

exec("openssl s_client -connect www.domain.com:443 -sslv2 > results.txt");

My question is how can I then read the file "results.txt" and look for certain sentence.. For example if the following exists in the text file:

no peer certificate available

Then return "no results found".

The reason for this is the results.txt may contain alot of data but I don't want to return it all using $getresults = file_get_contents('results.txt');

user3436467
  • 1,763
  • 1
  • 22
  • 35
  • Possible duplicate? http://stackoverflow.com/questions/13246597/how-to-read-a-file-line-by-line-in-php – Mike Apr 28 '15 at 04:45
  • Then what is it exactly that you want to do? That answer shows you how to read a file line by line, so once you find the text you want, you stop reading the rest of the file. – Mike Apr 28 '15 at 04:54

1 Answers1

1

speed string search in PHP

exec('grep "no peer certificate available" results.txt -b', $result);
var_dump($result);

Does it do the job to go on the right way ?

Community
  • 1
  • 1
zeflex
  • 1,487
  • 1
  • 14
  • 29
  • actually, this will not work for me since i am using windows.. not linux.. grep is not a valid command. so ill need a solution that will read the results.txt file – user3436467 Apr 28 '15 at 05:02
  • 1
    @user3436467 Grep is available for Windows. – Marty Apr 28 '15 at 05:03
  • ok installed grep, ran the code and got this `array(1) { [0]=> string(32) "24:no peer certificate available" }` – user3436467 Apr 28 '15 at 05:09