Chirag Shah
Chirag Shah

Reputation: 1474

Find String withing particular file using grep command in php

I am upload one file which is PDF file and I want to search particular word contains in uploaded

File using only grep command in php.

Thanks in advance.

Upvotes: 0

Views: 1821

Answers (2)

Firielentul
Firielentul

Reputation: 193

As Amal Murali wrote in comment, you have to convert PDF content to text. This has been already solved at StackOverflow, ie How to extract text from the PDF document?. Then you can use preg_match_all, or if you really want to use grep, you can use something as proc_open and pass the text through pipe.

So, using class from http://pastebin.com/hRviHKp1 (link from article), here is an example with preg_match_all:

include('class.pdf2text.php');
$a = new PDF2Text();
$a->setFilename('Videographer_RFP.pdf');
$a->decodePDF();
preg_match_all ('some pattern', $a->output(), $matches);
print_r($matches);

Note that I have not tested the code.

Upvotes: 2

linux_fanatic
linux_fanatic

Reputation: 5177

You can use pdfgrep see this link How to search contents of multiple pdf files? I have also used it few times and it also supports recursive search.

Thanks & Regards,
Alok Thaker

Upvotes: 2

Related Questions