php脚本中的双引号回显

问题描述:

我有一行php代码,如下所示:

I have a line of php code that looks like this:

echo "<script>$('#edit_errors').html('<h3><em>Please Correct Errors Before Proceeding</em></h3>')</script>";

我想知道如何正确地为文本添加字体颜色。
如果我这样做:

I would like to know how to add a font color to the text correctly. If I do this:

echo "<script>$('#edit_errors').html('<h3><em><font color="red">Please Correct Errors Before Proceeding</font></em></h3>')</script>";

单词red是黑色文本,编译器会抛出错误。

The word "red" is in black text and the compiler throws an error.

如果我在红色周围使用单引号,则文本根本不显示。

If I use single quotes around red, then the text does not show up at all.

任何帮助都会很棒。
谢谢

Any help would be great. Thanks

你需要逃避,所以它不会被解释为字符串的结尾。使用 \ 来逃避它:

You need to escape ", so it won't be interpreted as end of string. Use \ to escape it:

echo "<script>$('#edit_errors').html('<h3><em><font color=\"red\">Please Correct Errors Before Proceeding</font></em></h3>')</script>";

阅读更多:字符串转义序列