TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-26-2007, 08:25 AM   #1 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Smile 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
meshi is offline  
Reply With Quote
Old 10-26-2007, 10:11 AM   #2 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

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 :)
bluesaga is offline  
Reply With Quote
Old 10-26-2007, 01:37 PM   #3 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

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
meshi is offline  
Reply With Quote
Old 10-26-2007, 02:10 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Change file_get_contents('$row[path]') to file_get_contents($row['path']).
Salathe is offline  
Reply With Quote
Old 10-26-2007, 03:29 PM   #5 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

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?
meshi is offline  
Reply With Quote
Old 10-26-2007, 05:38 PM   #6 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

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.
bluesaga is offline  
Reply With Quote
Old 10-26-2007, 06:06 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.

Last edited by Salathe : 10-26-2007 at 09:05 PM.
Salathe is offline  
Reply With Quote
Old 10-26-2007, 09:04 PM   #8 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

News to me, thanks for that Salathe :)
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 10-30-2007, 09:20 AM   #9 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

thanks guys..really help me.i will check it out..thank you
meshi is offline  
Reply With Quote
Old 10-30-2007, 09:27 AM   #10 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

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?
meshi is offline  
Reply With Quote
Old 10-30-2007, 06:45 PM   #11 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

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.
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 11-01-2007, 04:43 PM   #12 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Default

ok thanx guys.
meshi is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:11 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design