Tommo Posted March 1, 2012 Share Posted March 1, 2012 So hi, Currently i'm trying to write to this file on my webserver. Everything works as it should, besides the fact that every time i use a apostrophe or a quotation mark there appears a back slash. ex. I type I'm -> It comes back I\'m or ex. class="hi" -> class=\"hi\" I tried putting in the stripslashes() function, but i kept getting error messages. Also, usually when you use stripslashes it also only removes the backslashes from view, but they're actually still there in the file. That's why it needs to be able to completely clean from the backslashes in the actual textfile. The text in this file (the textfile.txt) is going to be include()'d on a webpage. It is going to work as an online editor for some sort of navigation system i'm working on for shits and giggles. But i'm currently stuck with. (Also, i haven't written this script myself, but i have found it like this on the internet) <?php if($_POST['Submit']){ $open = fopen("textfile.txt","w+"); $text = $_POST['update']; fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("textfile.txt"); foreach($file as $text) { echo $text."<br />"; } }else{ $file = file("textfile.txt"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; } ?> Here's a running version on my host. http://php.utommo.com/writetext2/ Quote Link to comment Share on other sites More sharing options...
Guest The_Monkey Posted March 2, 2012 Share Posted March 2, 2012 Come on and talk with me. We can work it out. Quote Link to comment Share on other sites More sharing options...
Papa John Posted March 2, 2012 Share Posted March 2, 2012 (edited) You really don't need to use $PHP_SELF action="" That will post to the current page, and if you want a record that something actually happened (if the page refresh wasn't enough) action="#" That will append a # at the end of the URL to show the form was submitted. <?php if($_POST['Submit']){ $open = fopen("textfile.txt","w+"); $text = stripslashes(stripslashes($_POST['update'])); fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("textfile.txt"); foreach($file as $text) { echo $text . "<br />"; } }else{ $file = file("textfile.txt"); echo '<form action="" method="post">'; echo '<textarea Name="update" cols="50" rows="10">'; foreach($file as $text) { echo $text; } echo "</textarea>"; echo '<input name="Submit" type="submit" value="Update" />' . "\n" .'</form>'; } ?> That should fix it...but you probably should recursively stripslashes or use regex to get it -.- Edited March 2, 2012 by Papa John Quote Link to comment Share on other sites More sharing options...
Tommo Posted March 2, 2012 Author Share Posted March 2, 2012 You really don't need to use $PHP_SELF action="" That will post to the current page, and if you want a record that something actually happened (if the page refresh wasn't enough) action="#" That will append a # at the end of the URL to show the form was submitted. <?php if($_POST['Submit']){ $open = fopen("textfile.txt","w+"); $text = stripslashes(stripslashes($_POST['update'])); fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("textfile.txt"); foreach($file as $text) { echo $text . "<br />"; } }else{ $file = file("textfile.txt"); echo '<form action="" method="post">'; echo '<textarea Name="update" cols="50" rows="10">'; foreach($file as $text) { echo $text; } echo "</textarea>"; echo '<input name="Submit" type="submit" value="Update" />' . "\n" .'</form>'; } ?> That should fix it...but you probably should recursively stripslashes or use regex to get it -.- Thank you so much! So far it looks like it is doing what i need it to do. So i will continue to mess around with it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.