rebourne Posted May 27, 2007 Share Posted May 27, 2007 Hi, thanks ahead of time to anyone who takes the time to read this. I have a php script that creates a php file with user-specified content. THis is all well and good, however, I wish to include a php script within the content of the created file. I run into the problem when I insert php tags, to specify php code, in the $content variable of the file. Is there a way I can insert a small snippet of php when creating a file? (So the created file will have the php code in it, as php when it is created.) Thanks, I will be glad to clarify if this if it's hard to follow. Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/ Share on other sites More sharing options...
genericnumber1 Posted May 27, 2007 Share Posted May 27, 2007 <?php $contents = '<?php echo "hi"; ?>'; file_put_contents('myfile.php', $contents); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-262904 Share on other sites More sharing options...
rebourne Posted May 27, 2007 Author Share Posted May 27, 2007 Ahh thank you... For some reason when I had tried to treat it like html tags before, I kept getting T_CONSTANT_VARIABLE unexpected errors... Seems to be working now. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-262919 Share on other sites More sharing options...
rebourne Posted May 28, 2007 Author Share Posted May 28, 2007 <?php echo "<form method="post" action="/create.php"> <p>Password: <input type="password" name="truepassword" size="30"/></p><BR> <p><input type="submit" value="Submit"/></p> </form> "; if ($truepassword = $des_password) { echo "Password Correct"; } else { echo "Login to edit your profile"; } ?> <center> Username: one<BR> Password: \'\'<BR> True Password: <BR> Des Password: \'\'<BR> Other Information: This is the output of create.php which creates the file with the above contents. When I try to view this file through the browser, I get an "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../one.php on line 3" (The "..." is the dir/path to the file, which shouldn't be needed to work the problem..) I have worked on trying to solve this problem since your first reply... No luck. I don't understand where it expects the "," or ";", I am trying to have the created page echo an html form where it can process a password. (Note that the action=/create.php will change to something like action=<? PHP_SELF?> sometime later on, since it is itself that will process the info from the form... If I can get the form working....) Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-262944 Share on other sites More sharing options...
genericnumber1 Posted May 28, 2007 Share Posted May 28, 2007 problem you have is you're using double quotes too much... echo "<form method="post" action="/create.php"> <p>Password: <input type="password" name="truepassword" size="30"/></p><BR> <p><input type="submit" value="Submit"/></p> </form> "; should be echo '<form method="post" action="/create.php"> <p>Password: <input type="password" name="truepassword" size="30"/></p><BR> <p><input type="submit" value="Submit"/></p> </form> '; (note the quotes) it should also be "$truepassword == $des_password" Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-262979 Share on other sites More sharing options...
rebourne Posted May 28, 2007 Author Share Posted May 28, 2007 Then I get Parse error: syntax error, unexpected T_STRING in .../create.php on line 164 Code segment for /create.php: (Line 161) $content = ' (Line 162) <?php (Line 163) echo (Line 164) '<form method="post" action="/create.php"> (Line 165) <p>Password: <input type="password" name="truepassword" size="30"/></p><BR> (Line 166) <p><input type="submit" value="Submit"/></p> (Line 167) </form> (Line 168) '; Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-262991 Share on other sites More sharing options...
genericnumber1 Posted May 28, 2007 Share Posted May 28, 2007 the problem is that you're using a single quote and then using a single quote within your $content, so it can't tell where you want the variable assignment to end and the rest of the code to continue, here's an article on escaping quotes... http://www.hudzilla.org/phpbook/read.php/2_6_2 Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-263115 Share on other sites More sharing options...
rebourne Posted June 3, 2007 Author Share Posted June 3, 2007 Thanks, I appreciate your help. Works, finaly . Quote Link to comment https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/#findComment-267435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.