Re: Searching MS Word Docs
| From: | Todd Williamsen | Date: | Mon, 11 Feb 2002 17:46:44 +0000 |
| Subject: | Re: Searching MS Word Docs | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-11983@lists.php.net to get a copy of this message | ||
Nicole..
Here is the final code that searches all documents, except .DOC format
<?
include "variables.php";
$delimiter = ",";
$connection = @mysql_connect($databaseserver, $databaseuser, $databasepass)
or die ("could not connect to database");
$db = @mysql_select_db($databasename, $connection) or die("Could not select
database");
$sql = "SELECT id, FirstName, LastName, ResumeUp FROM $canidatetable";
$result = mysql_query($sql, $connection) or die("Couldn't execute query");
while ($row = mysql_fetch_array($result))
{
$found_it=0;
$id = $row['id'];
$FirstName = $row['FirstName'];
$LastName = $row['LastName'];
$filename = "/home/sites/madden.williamsen.net/web/recruiter/resumes/"
.$row['ResumeUp'];
$fd = fopen($filename,"r");
$contents = fread($fd, filesize($filename));
$keywords = explode( $delimiter, $words );
for ($i=0; $i < count($keywords); $i++) {
$kw = $keywords[$i];
if( eregi($kw, $contents) )
{
$found_it=1;
//set var to show a success - don't reset
$found_at_least_one=1;
}//end if
}//end for
if($found_it==1)
{
echo "The Words <b>$kw</b> has been found in the resume of
<a href=\"show_can.php?id=$id\">$LastName, $FirstName</a>
<br>";
}//end if
}//end while
if(!$found_at_least_one) echo "Your Search Returned Zero Records<br>";
fclose($fd);
?>
"Nicole Amashta" <430ntr3k@bellsouth.net> wrote in message
news:20020208213322.81528.qmail@pb1.pair.com...
> Say you entere keywords on the form. If you enter more than one word, you
> need to break them up before using the regex.
>
> This is good for one word at a time, other wise your search will be to
> specific.
>
> So, let a user add comma separated or space separated keywords like so:
>
> ex1. programmer, php, java, sql
>
> ex2. programmer php java sql
>
> Then, you should break the keyword string up into substrings, each
substring
> being a keyword.
>
> So,
> ## a space, or use a comma if allow user to separate by comma, or whatever
> character as a delimiter
>
> $delimiter = " ";
> $keywords = explode( $delimiter, $words ); ## this will generate an array
of
> keywords from the $words string
>
> so now add this to your code:
>
> <snip>
>
> $delimiter = " "; ## a space in this case, but you can change to whatever
> you want
>
> while ($row = mysql_fetch_array($result))
> {
> $id = $row['id'];
>
> $FirstName = $row['FirstName'];
>
> $LastName = $row['LastName'];
>
> $filename = $row['ResumeUp'];
>
> $fd =
>
fopen("/home/sites/madden.williamsen.net/web/recruiter/resumes/$filename","r
> ");
>
> $contents = fread($fd, filesize($filename));
>
> fclose($fd);
>
> $keywords = explode( $delimiter, $words ); ## this will generate an
array
> of keywords from the $words string
>
> ## now loop through the array keywords and search for each keyword
>
> for ($index=0; $index < count($keywords); $index++)
>
>
> $keyword = $keywords[$idx];
>
> if( eregi($keyword, $contents) ) {
>
> echo "The Words <b>$keywords</b> has been found in the resume of
>
> <ol><li>$LastName, $FirstName <a
>
>
>
href=\"http://madden.williamsen.net/recruiter/resumes/basename($filename)\">
>
> Resume</a></li></ol>";
> }
> else {
> echo "The keyword $keyword was not found in the resume
> $filename<br>";
> }
> } ## end for loop
> }
> </snip>
>
> "Nicole Amashta" <430ntr3k@bellsouth.net> wrote in message
> news:20020208212506.72791.qmail@pb1.pair.com...
> > What keywords are being used? IF they aren't found, then nothing is
being
> > printed out. YOu need to add the else clause to this:
> >
> > if ( eregi (..... ) ) {
> > }
> > else { ## add this to catch if keywords not found for debugging
purposes
> at
> > least so you see what is not found
> >
> > echo "The keywords $keywords were not found in the resume $filename
> <br>";
> > }
> >
> >
> > This is so you can at least see nothing is being found.
> >
> > ====================
> >
> > "Todd Williamsen" <todd@williamsen.net> wrote in message
> > news:20020208211737.65998.qmail@pb1.pair.com...
> > > here is the code:
> > > returns nothing, not even an error... the process is fast too, so I
> know
> > it
> > > isn't doing anything...
> > >
> > > GRR!
> > >
> > > <?
> > > $connection = @mysql_connect($databaseserver, $databaseuser,
> > $databasepass)
> > > or die ("could not connect to database");
> > > $db = @mysql_select_db($databasename, $connection) or die("Could not
> > select
> > > database");
> > > $sql = "SELECT id, FirstName, LastName, ResumeUp FROM $canidatetable
";
> > > $result = mysql_query($sql, $connection) or die("Couldn't execute
> query");
> > > if ($result)
> > > {
> > > if (($numrows = mysql_num_rows($result)) > 0)
> > > {
> > > while ($row = mysql_fetch_array($result))
> > > {
> > > $id = $row['id'];
> > > $FirstName = $row['FirstName'];
> > > $LastName = $row['LastName'];
> > > $filename = $row['ResumeUp'];
> > > $fd =
> > >
> fopen("/home/sites/madden.williamsen.net/web/recruiter/resumes/$filename",
> > > "r");
> > > $contents = fread($fd, filesize($filename));
> > > fclose($fd);
> > > $keyword = "$words";
> > > if(eregi($keyword, $contents))
> > > echo "The Words <b>$keywords</b> has been found in the resume of
> > > <ol><li>$LastName, $FirstName <a
> > >
> >
>
href=\"http://madden.williamsen.net/recruiter/resumes/basename($filename)\">
> > > Resume</a></li></ol>";
> > > }
> > > }
> > > else {
> > > echo "Therer are no resumes posted yet";
> > > }
> > > }
> > > else {
> > > echo "Error Performing Query";
> > > }
> > > ?>
> > >
> > >
> > >
> >
> >
>
>