PHP file_put_contents或fwrite'和“字符

时间:2021-11-15 20:23:35

Hey guys, how do I write " and ' characters when I'm doing it via PHP eg

嘿伙计们,当我通过PHP做这件事时,我怎么写“和'字符

<?php
$newFile = "<?php echo 'quote: "hello world"'; ?>"
file_put_contents('index.php', $newFile);
 ?>

Thanks

3 个解决方案

#1


2  

\ is used to 'escape' things.

\用于“逃避”事物。

$newfile = "<?php echo 'quote: \"hello world\"'; ?>";

#2


1  

You can only use one sort of quotes in a string literal. If another quote is to appear within the literal it needs to be escaped by a \

您只能在字符串文字中使用一种引号。如果另一个引用出现在文字中,则需要通过\

$newFile = "<?php echo 'quote: \"hello world\"'; ?>";
file_put_contents('index.php', $newFile);

#3


0  

$newFile = "<?php echo 'quote: \"hello world\"'; ?>"

Read this Strings manual.

阅读此字符串手册。

#1


2  

\ is used to 'escape' things.

\用于“逃避”事物。

$newfile = "<?php echo 'quote: \"hello world\"'; ?>";

#2


1  

You can only use one sort of quotes in a string literal. If another quote is to appear within the literal it needs to be escaped by a \

您只能在字符串文字中使用一种引号。如果另一个引用出现在文字中,则需要通过\

$newFile = "<?php echo 'quote: \"hello world\"'; ?>";
file_put_contents('index.php', $newFile);

#3


0  

$newFile = "<?php echo 'quote: \"hello world\"'; ?>"

Read this Strings manual.

阅读此字符串手册。