php在变量中写入双引号的文件

时间:2015-11-02 08:57:26

标签: php json html5 double-quotes

当我尝试将" text "从变量写入文本文件时,我遇到了问题。当一段文本附带double quotes时,不会创建该文件。我尝试了几件事似乎没什么用。到现在为止,我必须避免写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 = "\n"; $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.'); } ?> 中的代码:

clock = [0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1]

澄清一些事情:我从&#34;字符串化&#34;得到文本。来自HTML5前端页面的JSON变量,我将此文本写入文件,但如果它带有双引号,则不会写入任何内容。

感谢

0 个答案:

没有答案