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?

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.