I'm having problems when I try to write doble quotes
from a variable into a text file. When a piece of text comes with a " text "
the file is not created. I tried several things but nothing seems to work. By now I have to avoid write double quotes
.
Here is my code in PHP
:
<?php
$data = json_decode(stripslashes($_POST['data']));
$name = json_decode(stripslashes($_POST['name']));
$url_to = json_decode(stripslashes($_POST['url_to']));
$saveToFile = $url_to . $name . '.srt';
$space = "
";
$blank = " ";
$arrow = " --> ";
if (isset($data))
{
$h = fopen($saveToFile, 'w+');
if ($h) {
foreach ($data as $sub) {
fwrite($h,$sub->number);
fwrite($h,$space);
fwrite($h,$sub->start);
fwrite($h,$arrow);
fwrite($h,$sub->end);
fwrite($h,$space);
if(strpos($sub->text,'"')!==false){
$sub->text = str_replace('"',"'",$sub->text);
fwrite($h,$sub->text);
} else {
fwrite($h,$sub->text);
}
fwrite($h,$space);
fwrite($h,$space);
}
fclose($h);
}
exit('Data Saved.');
}
?>
To clarify some things: I get the text from a "stringified" JSON variable coming from a HTML5 front end page, and I write this text to a file, but if it comes with a double quote, nothing is written.
thanks