Jump to content

Cleaning up special characters


MilkEyedMender

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.