I've created a 'update' news page to update my sites news via a web browser. ive linked a file called news.txt (which contains the news) to index.php. THis file loads fine - no probs.
I created an update page with this code:
<?php
$file = file_get_contents("news.txt");
echo '<textarea name="textarea2" cols="100" rows="10">' . $file . '</textarea>';
When the page loads, the news.txt file is loaded into a text are so I can edit it. Below the text area is an update button that points to update.php. The file contains this code:
<?php
$file = 'news.txt';
$contents = @$_POST['textarea2'];
if(empty($contents) || $contents == '')
die('No update information given.');
if(!is_writeable($file))
die('File [<span style="font-style: italic;">'.$file.'</span>] not writeable. Check permissions.');
$fp = fopen($file, 'w');
if(!$fp)
die('Opening of file [<span style="font-style: italic;">'.$file.'</span>] failed.');
if(fwrite($fp, $contents) === false)
die('Writing to file [<span style="font-style: italic;">'.$file.'</span>] failed!!');
fclose($fp);
print"News updated!!";
print"<a href=\"news.php\">Back</a>";
?>
This script works fine too. Once Ive edited the textarea with the news and click 'update', the file updates with no problems apart from one.
If I add new content to the news, when I click update, the script adds backslashes to any speechmarks in the file. For example, If I added:
Forums updated! <a href="forums.php" terget="blank">Forums</a>
It would add the news like this:
Forums updated! <a href=\"forums.php\" terget=\"blank\">Forums</a>
I know in some PHP files, you need to put forward slashes before speach marks but every time the news is updated, it adds another forward slash. If I added the above example and then updated the file again with five other news updates, it would apear like this:
Forums updated! <a href=\\\"forums.php\\\" terget=\\\"blank\\\">Forums</a>
Its anoying as it is messing up any links I add to the news as well. WHy is this happening? I cant figure it out!
Ive noticed now that it adds between 2-5 backslashes during an update. Help! 🙁