943,879 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2295
  • PHP RSS
Apr 5th, 2009
0

Script to add url to text file

Expand Post »
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wxflint is offline Offline
15 posts
since Jan 2009
Apr 5th, 2009
0

Re: Script to add url to text file

Quote 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.
Quote originally posted by PHP.net ...
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
May 21st, 2010
0
Re: Script to add url to text file
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.


If you are having problems, post up your code for us to look at.
This is the text file that I would like to add a url to.

file:///C:/Documents%20and%20Settings/owner/my%20documents/my%20$10.00%20investment.txt
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tazzz1 is offline Offline
2 posts
since May 2010
May 21st, 2010
0
Re: Script to add url to text file
This is the text file that I would like to add a url to.

file:///C:/Documents%20and%20Settings/owner/my%20documents/my%20$10.00%20investment.txt
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tazzz1 is offline Offline
2 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: automatic image changing
Next Thread in PHP Forum Timeline: SQL Query - max count?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC