Welcome to the OZONE Asylum FAQWiki!
Frequently Asked Questions
Server Side Coding
PHP

How do I search PDF-files with PHP? Pages that link to <a href="https://ozoneasylum.com/backlink?for=21295" title="Pages that link to How do I search PDF-files with PHP?" rel="nofollow" >How do I search PDF-files with PHP?\

To search inside PDF files with PHP usually requires some sort of PDF-package to be installed on your server.
I wanted a simpler way and based this on a class from here: http://www.phpclasses.org/browse.html/package/702.html

I then did a quickie class that handles a very simple search in different kinds of files.
If the file is a pdf it uses the class pdf_search.

As you instansiate the class pass the following:
A valid path to the directory you want to search incl trailing "/"
A string of words to search for separated with a space.
(this class searches like this <word> OR <word> OR <word>...)
A 0 (zero) for non-recursive directory
I don't have time right now to be able to handle recursive searches from the given directory.
Last invoke the method searchInFile();
That's about it.

Oh, IMPORTANT!
This seems to work fine on Linux
BUT...
The pdf search part will not work on Windows, at least not with a default php 4.23 installation from phpdev. It either chrashes on the "gzuncompress()" or as it parses the regexp in the method textline()
Don't know why.

Examples are in the code.
See output: http://www.dmsproject.com/test/pdf/searchDoc.php
See code: http://www.dmsproject.com/test/pdf/searchDoc.phps


Have fun Dan

(Created by DmS on 04-11-2004 12:20)

« BackwardsOnwards »

Show Forum Drop Down Menu