MilkEyedMender Posted October 31, 2008 Share Posted October 31, 2008 Essentially, I'm making a small webpage for a project that allows people to enter text into a box. The main page is in HTML, and uses PHP to pass that text into a text file. The site also randomly loads a line of text from that text file onto the homepage, which serves as the prompt for the next person. My problem is characters like a single quote ', to which ends up being \' is appended when it writes to a text file. Here's the PHP I'm using to send the input data to the text file. <?php $ourFileName = "database.txt"; $fh = fopen($ourFileName, 'a') or die ("Can't open file."); $stringData = $_POST["sayanything"]; fwrite($fh, $stringData); //fwrite($fh, "BREAK"); $blankSpace = "\n"; fwrite($fh, $blankSpace); fclose($fh); ?> If it's useful, here's the PHP that's embeded in the HTML for reading a line from the text file. <?php $lines = file('database.txt'); $l_count = count($lines); for ($x = 0; $x<$l_count; $x++) { } $linemax = $l_count; $randline = rand(0, $linemax-1); echo $lines[$randline] ?> I just need help with a small loop that will go through either the input as it's stored or the data that's read before it's displayed that gets rid of the \. So if I typed "There's no replacement for places," it ends up being "There\'s no replacement..." I randomly decided to do this as part of a project for school, and I've had to learn the HTML and PHP, so I have limited knowledge. I really have no clue, so any pointers would be appreciated. Thank you all! Link to comment https://forums.phpfreaks.com/topic/130838-cleaning-up-special-characters/ Share on other sites More sharing options...
mapleleaf Posted October 31, 2008 Share Posted October 31, 2008 My guess is you have magic qoutes on You can try echo stripslashes($lines[$randline]); Link to comment https://forums.phpfreaks.com/topic/130838-cleaning-up-special-characters/#findComment-679082 Share on other sites More sharing options...
MilkEyedMender Posted October 31, 2008 Author Share Posted October 31, 2008 That does it. Thanks a lot. I just started reading my HTML/PHP book a week ago, so there's a lot I don't know. Link to comment https://forums.phpfreaks.com/topic/130838-cleaning-up-special-characters/#findComment-679087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.