PHP file_put_contents或fwrite\'和\\“字符

问题描述

|| 大家好, 通过PHP编写\“和\'字符时如何进行 例如
<?PHP
$newFile = \"<?PHP echo \'quote: \"hello world\"\'; ?>\"
file_put_contents(\'index.PHP\',$newFile);
 ?>
谢谢     

解决方法

\\
用于“逃避”事物。
$newfile = \"<?php echo \'quote: \\\"hello world\\\"\'; ?>\";
    ,您只能在字符串文字中使用一种引号。如果在文字中出现另一个引号,则需要用ѭ1进行转义。
$newFile = \"<?php echo \'quote: \\\"hello world\\\"\'; ?>\";
file_put_contents(\'index.php\',$newFile);
    ,
$newFile = \"<?php echo \'quote: \\\"hello world\\\"\'; ?>\"
阅读此字符串手册。