Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with code to add a line to the end of a txt file
Old 04-07-2005, 09:16 PM Help with code to add a line to the end of a txt file
HaRRo's Avatar
SEO Expert

Latest Blog Post:
The Large Hadron Collider
Posts: 522
Location: United Kingdom
Trades: 0
Hey all im wondering if anyone knows of a way to help me

I made a AI bot that responds via questions and answers from a txt file

It uses a txt file in the format of this

Question;Answer;

I want users to be able to add there own questions and answers but i want to make a form
To add them

The form would need 2 boxes and a submit button to add to /data/data.txt

Any ideas?
Any full code would be highly helpful!
And a spam filter would be even better like on words *spam* *http* dont submit

The form would need to add the data to the last line on the data file
Much appreciated
David
__________________

Please login or register to view this content. Registration is FREE

What are you waiting for? Easy $$$ anyone can make a fortune!
CLICK CLICK CLICK CLICK CLICK CLICK CLICK CLICK CLICK
HaRRo is offline
Reply With Quote
View Public Profile Visit HaRRo's homepage!
 
 
Register now for full access!
Old 04-07-2005, 10:24 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Use fopen() to get a file pointer to the file you want to work with. Open it with the append mode (which means content is added onto the end of the file). Then, write your content to the file with fwrite().

PHP Code:
$fp fopen('/data/data.txt''a') or die('Could not open file for writing');

$content "$_POST[question];$_POST[answer];\n";

fwrite($fp$content) or die('Could not write to file.');

fclose($fp); 
Something like that.

As for filtering, you can do a simple search for keywords. This is an example of an extremely simple technique.
PHP Code:
$keywords = array('spam''http''www''poker');

foreach(
$keywords as $word)
    if(
stripos($content$word) !== false)
        die(
'Sorry, we found some common spam words in your post.'); 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-08-2005, 07:47 AM
HaRRo's Avatar
SEO Expert

Latest Blog Post:
The Large Hadron Collider
Posts: 522
Location: United Kingdom
Trades: 0
perfect thanks
__________________

Please login or register to view this content. Registration is FREE

What are you waiting for? Easy $$$ anyone can make a fortune!
CLICK CLICK CLICK CLICK CLICK CLICK CLICK CLICK CLICK
HaRRo is offline
Reply With Quote
View Public Profile Visit HaRRo's homepage!
 
Reply     « Reply to Help with code to add a line to the end of a txt file
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64176 seconds with 12 queries