954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Script to add url to text file

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: Sample.

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?

wxflint
Newbie Poster
17 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 
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.

<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    // In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }

    echo "Success, wrote ($somecontent) to file ($filename)";

    fclose($handle);

} else {
    echo "The file $filename is not writable";
}
?>

If you are having problems, post up your code for us to look at.

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 

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

tazzz1
Newbie Poster
2 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

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

tazzz1
Newbie Poster
2 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You