how to write variables value with file_put_contents()?

前端 未结 5 1061
北海茫月
北海茫月 2021-01-21 10:28

Have been trying to figure this out all day assuming its just a small error.....

I\'m trying to use the file_put_content to put a variables value into anoth

5条回答
  •  青春惊慌失措
    2021-01-21 11:22

    Change the single quotes surrounding the string you are writing to the file to doubles quotes. So:

    file_put_contents("/home/files/1/741/html/WP/$GDI_user/config.php",'');
    

    ...becomes...

    file_put_contents("/home/files/1/741/html/WP/$GDI_user/config.php","");
    

    A couple of thoughts on this operation

    • Don't use PHP short tags - use instead of as short tags are not supported everwhere and are disabled by default on new PHP installations
    • Don't put new-line literals in the middle of quoted strings, use HEREDOC syntax if you want to do that. It's best to avoid this if possible as it can lead to cross-platform compatibility issues. Use \r, \n, \r\n and the PHP_EOL constant instead.
    • Read this thoroughly so you know exactly what you can and can't do, and where.

提交回复
热议问题