TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   how to search the content of txt file (http://www.talkphp.com/absolute-beginners/1343-how-search-content-txt-file.html)

meshi 10-26-2007 08:25 AM

how to search the content of txt file
 
[code]input type="text" name="keyword"><input type="submit" name="search" value="Search>[code]


PHP Code:

$sql=mysql_query("select * from myfile");
while (
$row=mysql_fetch_array($sql))
{

$file_handle fopen("$row[path]""r");
fclose($file_handle);



if i have a file in my database george.txt and totz.txt
george.txt content:

a b c d e f g h i j k l m n o p q r s t u v w x y z

totz.txt content:

one two three four five six seven eight nine ten

if i enter the word one in the input box and then click search, the display should be totz.txt. how would i do to make that posible..please give me an example

bluesaga 10-26-2007 10:11 AM

While i do not recommend this, as it does not scale well at all, and you would be better off inputting the information to mysql and search using the FULLTEXT boolean/LIKE search tools over this method.. It IS possible however:


PHP Code:

<?php
if($_REQUEST['search'])
{
  
$sql=mysql_query("select * from myfile");
  while (
$row=mysql_fetch_array($sql))
  {

    
$file_handle fopen("$row[path]""r");
    
$contents fread($file_handlefilesize($row[path]));
    
fclose($file_handle);
    
$iPos stripos($contents$_REQUEST['search']);

    if (
$iPos !== false
      print 
$row[path]; //Output filename.txt if search is found.
  
}  
}
?>
<form>
<input type=text name=search><input type=submit name=submit value=submit>
</form>

note, this is a HORRIBLE way of doing this and i would definitely recommend you look at some generalised PHP tutorials before going further. Spend some time learning the fundamentals and it really does help :)

meshi 10-26-2007 01:37 PM

oh!!thank u very much blue saga.i have tried also doing that but like what u said is not recommended..if i insert the data into my database like this one

PHP Code:

[if (isset($_POST[search]))
{
echo 
"amew";
$sql=mysql_query("select * from table"); 
while (
$row=mysql_fetch_array($sql)) 

mysql_query("update candidate_CV content='".mysql_real_escape_string(file_get_contents('$row[path]'))."' where candidate_id='$row[candidate_id]'");
}



please correct my code..i want to update the content of the file into mytable.it has an error in file get contents

Salathe 10-26-2007 02:10 PM

Change file_get_contents('$row[path]') to file_get_contents($row['path']).

meshi 10-26-2007 03:29 PM

ok.thanks salathe.i have 1 problem.if i have a doc type file and i want to open it i should convert it first to txt.my problem is i dont know a script that convert doc to txt.i saw on internet this code

[php]
$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Documents->Open($filename);
$new_filename = substr($filename,0,-4) . ".txt";
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($new_filename,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);

$fh = fopen($new_filename, 'r');
$contents = fread($fh, filesize($new_filename));
fclose($fh);
unlink($new_filename);
[php]

i tried to run this but theres an error on it class COM is not defined what does that mean?

bluesaga 10-26-2007 05:38 PM

It means the class is not defined, ie doesn't exist. You need to have all the files that come with the script.... Check PHP classes.

http://www.phpwordlib.motion-bg.com/ looks good.

Salathe 10-26-2007 06:06 PM

COM is a part of the PHP core (formerly a PHP extension before PHP5) for Windows, to allow working with external programs. Since you're getting the "not defined" error then you're either not on Windows or are using PHP4 without the COM extension installed. Using the COM, as in the example code that you posted, allows PHP to actually talk to Word itself, directly, rather than just manipulating the doc file in PHP.

Edit: Here's a link to the COM Documentation in the PHP manual.

bluesaga 10-26-2007 09:04 PM

News to me, thanks for that Salathe :)

meshi 10-30-2007 09:20 AM

thanks guys..really help me.i will check it out..thank you

meshi 10-30-2007 09:27 AM

if i have a linux platform is it posible to run the COM if i will install wine and ms office?or its for windows platform only?

bluesaga 10-30-2007 06:45 PM

I would not say this is an ideal efficient method of doing this programming.

I would recommend getting a php only class that is not reliant on external sources.

meshi 11-01-2007 04:43 PM

ok thanx guys.


All times are GMT. The time now is 02:17 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0