使用撇号创建变量并双引号PHP

时间:2017-07-02 23:08:27

标签: php variables

如果你的大量数据中包含'和',那么如何创建变量whitout addslashes。

 <?
 // Create variable with single and double quote.

 s = ' massive data with """ and '''' inside.... ';

 ?>

我试试

 addslashes(s) = ' massive data in with """ and '''' inside.... ';

但我想我会想念一些事情。我不能手动改变每个撇号,因为它很大。

谢谢!

1 个答案:

答案 0 :(得分:1)

您正在寻找反斜杠转义字符:

$string = ' massive data in with """ and \'\'\'\' inside....';

只需在您希望被解释为字符串一部分的任何字符之前使用\

我已经创建了一个3v4l,演示了上面的代码 here

警告,如果您有一个包含两个单引号和双引号的大型文本字符串,则可以使用 heredoc 来避免需要逃避个人字符:

$str = <<<EOD
' massive data with """ and '''' inside.... ';
EOD;
echo $str;

我已经创建了另一个 here 的3v4l示例。

希望这有帮助! :)