开发者

PHP file_put_contents or fwrite ' and " characters

开发者 https://www.devze.com 2023-02-25 14:31 出处:网络
Hey guys, how do I write \" and \' characters when I\'m doing it via PHP eg <?php 开发者_如何学运维$newFile = \"<?php echo \'quote: \"hello world\"\'; ?>\"

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

<?php
开发者_如何学运维$newFile = "<?php echo 'quote: "hello world"'; ?>"
file_put_contents('index.php', $newFile);
 ?>

Thanks


\ is used to 'escape' things.

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


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);


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

Read this Strings manual.

0

精彩评论

暂无评论...
验证码 换一张
取 消