salve ragazzi...ho trovato questo script che dovrebbe fare una cosa fantastica..ovvero ricercare testi nei pdf con php
di seguito la classe.. e lo script
pdfsearch.php
Codice PHP:
<?
class pdf_search {
var $_buffer;
function pdf_search($buffer) {
$this->_buffer = $buffer;
}
// This function returns the next line from the document.
// If a stream follows, it is deflated into readable text.
function nextline() {
$pos = strpos($this->_buffer, "\r");
if ($pos === false) {
return false;
}
$line = substr($this->_buffer, 0, $pos);
$this->_buffer = substr($this->_buffer, $pos + 1);
if ($line == "stream") {
$endpos = strpos($this->_buffer, "endstream");
$stream = substr($this->_buffer, 1, $endpos - 1);
$stream = @gzuncompress($stream);
$this->_buffer = $stream . substr($this->_buffer, $endpos + 9);
}
return $line;
}
// This function returns the next line in the document that is printable text.
// We need it so we can search in just that portion.
function textline() {
$line = $this->nextline();
if ($line === false) {
return false;
}
if (preg_match("/[^\\\\]\\((.+)[^\\\\]\\)/", $line, $match)) {
$line = preg_replace("/\\\\(\d+)/e", "chr(0\\1);", $match[1]);
return stripslashes($line);
}
return $this->textline();
}
// This function returns true or false, indicating whether the document contains
// the text that is passed in $str.
function textfound($str) {
while (($line = $this->textline()) !== false) {
if (preg_match("/$str/i", $line) != 0) {
return true;
}
}
return false;
}
}
?>
script index.php
Codice PHP:
<?
include("pdfsearch.php");
$theDocument = "napoli.pdf";
$searchText = "Iervolino";
$fp = fopen($theDocument, "r");
$content = fread($fp, filesize($theDocument));
fclose($fp);
$pdf = new pdf_search($content);
if ($pdf->textfound($searchText)) {
echo "ho trovato $searchText.";
}else {
echo "$searchText non è stato trovato.";
}
?>
sapreste dirmi perchè mi da quest' errore?
Parse error: parse error, unexpected T_STRING in c:\programmi\easyphp1-7\www\searchpdf\pdfsearch.php(35) : regexp code on line 1
Fatal error: Failed evaluating code: chr(0²); in c:\programmi\easyphp1-7\www\searchpdf\pdfsearch.php on line 35
grazie mille