开发者

cant write varibles into php file using file_put_contents PHP

开发者 https://www.devze.com 2023-03-29 00:03 出处:网络
I\'m trying to edit a file using the file_put_contents Everything works fine (the data shows up in the test.php, well most of it) but the variables do not.

I'm trying to edit a file using the file_put_contents

Everything works fine (the data shows up in the test.php, well most of it) but the variables do not.

heres an example of my problem

code for the file that will perform the file_put_contents:

<?php
 file_开发者_C百科put_contents("test.php","<?

$title = "title_name_goes_here"
echo $title;

?>");
?>

Code that shows up in the target file (test.php):

<?

 = this_is_my_name
echo ;

?>

What should show up in test.php:

<?

    $title = "title_name_goes_here"
    echo $title;

    ?>

Also, I'm using Dreamweaver to write the code in and it seems to have problems (code errors) when i insert the quote for the $title's value so its ok if i used $title = title_name_goes_here but it doesn't like $title = "title_name_goes_here". When i say its okay, i mean dreamweaver doesn't show any code errors but it still doesn't do what it should.

any ideas?


Escape the quotes (and the dollar signs):

<?php
 file_put_contents("test.php","<?

\$title = \"title_name_goes_here\"
echo \$title;

?>");
?>

If you don't want to see the ugly escapes just use single quotes:

<?php
 file_put_contents('test.php",'<?

$title = "title_name_goes_here"
echo $title;

?>');
?>
0

精彩评论

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