A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearWriting PHP Code to a File - page 1
User InfoPosts
Writing PHP Code to a File#1
I am wondering if it is possible to write php code to a file. For example:

fwrite($handle, "<?php $var = $var2 ?>");

I would like it produce the exact string in the file and not the eval(ed code. Is this possible?

I am currently getting the following output (where $var = 1 and $var2 = 2):

<?php 1 = 2 ?>

Whereas I want the actual string:

<?php $var = $var2 ?>

Thanks for the help

posted date: 2009-04-09 05:50:00

Re: Writing PHP Code to a File#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-09 05:50:01

Re: Writing PHP Code to a File#3
You can use single quotes instead of double quotes, which do not expand inline variable names:fwrite($handle, (<?php $var = $var2 ?>();

posted date: 2009-04-09 05:52:00

Re: Writing PHP Code to a File#4
This has nothing to do with file io. Read about variable substitution and escaping in strings in PHP.

posted date: 2009-04-09 06:17:00

Re: Writing PHP Code to a File#5
double quoted strings are parsed for variables, and the variables value is inserted at that position. i suppose this is because php originally was designed as a thin webserver-database templating layer.personally, i don(t like that and never use double quotes because of this. instead, i always use single quotes and string concenation:<?php echo (hello, ( . $name; ?>does the same as: <?php echo "hello, $name"; ?>single quotes: syntax coloring works better, it(s (marginally) faster and errors are found easier

posted date: 2009-04-09 06:30:00

Re: Writing PHP Code to a File#6
Just escape the $ symbol<?phpfwrite($handle, "<?php \$var = \$var2 ?>");?>

posted date: 2009-04-11 23:39:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.