Script to add url to text file

Reply

Join Date: Jan 2009
Posts: 4
Reputation: wxflint is an unknown quantity at this point 
Solved Threads: 0
wxflint wxflint is offline Offline
Newbie Poster

Script to add url to text file

 
0
  #1
Apr 5th, 2009
I am looking for a php code to add a url to a text file like this
1- user adds url to a text box
2- user adds site name
3- user hits submit button

The url that was entered in to the text box is then added to a .txt file along with the site name and is phased threw as a link so when it is output it looks like this: <a href="http://sample.com/">Sample</a>.

I will then use an <? includes ("file.txt"); ?> to pull the txt file to the page i want it to.

The link then should look like Sample and is clickable.

Is this possible?
Live and Local Weather
http://wxflint.com
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Script to add url to text file

 
0
  #2
Apr 5th, 2009
Originally Posted by wxflint
Is this possible?
Yes.

It wouldn't take much research either. There are plenty of tutorials online for how to write to a file using PHP, including a good example on php.net.
Originally Posted by PHP.net
  1. <?php
  2. $filename = 'test.txt';
  3. $somecontent = "Add this to the file\n";
  4.  
  5. // Let's make sure the file exists and is writable first.
  6. if (is_writable($filename)) {
  7.  
  8. // In our example we're opening $filename in append mode.
  9. // The file pointer is at the bottom of the file hence
  10. // that's where $somecontent will go when we fwrite() it.
  11. if (!$handle = fopen($filename, 'a')) {
  12. echo "Cannot open file ($filename)";
  13. exit;
  14. }
  15.  
  16. // Write $somecontent to our opened file.
  17. if (fwrite($handle, $somecontent) === FALSE) {
  18. echo "Cannot write to file ($filename)";
  19. exit;
  20. }
  21.  
  22. echo "Success, wrote ($somecontent) to file ($filename)";
  23.  
  24. fclose($handle);
  25.  
  26. } else {
  27. echo "The file $filename is not writable";
  28. }
  29. ?>
If you are having problems, post up your code for us to look at.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC