Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php包含未终止的字符串文字消息_Php_Javascript - Fatal编程技术网

php包含未终止的字符串文字消息

php包含未终止的字符串文字消息,php,javascript,Php,Javascript,以下几点效果不错: var sFirstText=<?php include("first2.html"); ?>; var sFirstText=; 当first2.html如下所示时,包括双引号: "<p>sentence one</p><p>sentence two</p>" “第一句第二句” 但是,如果first2.html看起来像: "<p>sentence one</p> <p>s

以下几点效果不错:

var sFirstText=<?php include("first2.html"); ?>;
var sFirstText=;
当first2.html如下所示时,包括双引号:

"<p>sentence one</p><p>sentence two</p>"
“第一句

第二句

但是,如果first2.html看起来像:

"<p>sentence one</p>
<p>sentence two</p>"
“第一句话

第二句
我收到一条未终止的字符串文字消息。我希望弄清楚如何在不删除回车/换行序列的情况下包含html

此外,如果我删除双引号并执行以下操作:

var sFirstText="<?php include("first2.html"); ?>";
var sFirstText=”“;
这是行不通的,返回一条我还不能理解的信息


基本上,我希望在不删除cr/lf序列的情况下将简单的html格式设置到字段中。

尝试在行尾使用
\
将字符串继续到下一行。

尝试在行尾使用
\
将字符串继续到下一行。

此外,在获取源内容时,您需要转义用于包装它的引号类型

这是我要做的

function contents($file, $wrappingQuote='\'') {
    $fh = fopen($file,'r');
    $contents = fread($fh,filesize($file));
    fclose($fh);
    echo preg_replace('~\'~','\\'.$wrappingQuote,preg_replace('~\r?\n~','',$contents));
}
(……)

var-str='';
//或

var str=“Javascript无法处理这些换行符。您可能需要打开文件,读取内容,并用空格替换这些换行符

此外,在获取源内容时,您需要转义用于包装它的引号类型

这是我要做的

function contents($file, $wrappingQuote='\'') {
    $fh = fopen($file,'r');
    $contents = fread($fh,filesize($file));
    fclose($fh);
    echo preg_replace('~\'~','\\'.$wrappingQuote,preg_replace('~\r?\n~','',$contents));
}
(……)

var-str='';
//或

var str=“试试这个:
var sFirstText=”@dqlopez,导致“丢失”;在语句之前,但感谢您的思考。请尝试以下操作:
var sFirstText=''@dqlopez,导致“丢失”;请注意,您不需要在first2.html文件中使用任何类型的引号来包装您的代码。请注意,您不需要在first2.html文件中使用任何类型的引号来包装您的代码。这确实起到了作用,尽管我必须承认,当我第一次阅读它时,我非常肯定它不会起作用。活到老学到老。虽然我必须承认,当我第一次读到它的时候,我很确定它不会起作用。生活和学习。