简体   繁体   English

在PHP中使用grep命令查找包含特定文件的字符串

[英]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 我正在上传一个PDF文件,我想搜索上传的特定单词

File using only grep command in php. 在php中仅使用grep命令来文件。

Thanks in advance. 提前致谢。

You can use pdfgrep see this link How to search contents of multiple pdf files? 您可以使用pdfgrep看到此链接如何搜索多个pdf文件的内容? I have also used it few times and it also supports recursive search. 我也使用了几次,它还支持递归搜索。

Thanks & Regards, 感谢和问候,
Alok Thaker 阿洛·萨克(Alok Thaker)

As Amal Murali wrote in comment, you have to convert PDF content to text. 正如Amal Murali在评论中写道,您必须将PDF内容转换为文本。 This has been already solved at StackOverflow, ie How to extract text from the PDF document? 这已在StackOverflow中解决,即如何从PDF文档中提取文本? . 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. 然后,您可以使用preg_match_all,或者如果您确实要使用grep,则可以将其用作proc_open并将文本通过管道传递。

So, using class from http://pastebin.com/hRviHKp1 (link from article), here is an example with preg_match_all: 因此,使用http://pastebin.com/hRviHKp1中的类(文章链接),下面是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. 请注意,我尚未测试代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM