zfred09 Posted January 12, 2007 Share Posted January 12, 2007 Alright say that when a condition is met, an entirely new php file is created with fwrite() and there is no code in it. How do you automatically write php code into that file using a script? Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 [url=http://php.net/fwrite]fwrite[/url](). Quote Link to comment Share on other sites More sharing options...
zfred09 Posted January 12, 2007 Author Share Posted January 12, 2007 Yes I know fwrite writes to a file, maybe my question wasn't clear, how do I write php code to that new file, because this method below doesn't work with php, you get unexpected string errors.[code]$text = "<?php echo("hi dude"); $_SESSION['hello']="Hi"; ?>"; $file = "aaa.php"; if (!$my_file = fopen($file,"a")) { echo "Unable to open $file"; } if (!fwrite($my_file, $text)) { echo "Unable to write to $file"; } echo "Text entered into $file"; fclose($my_file); [/code] Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 12, 2007 Share Posted January 12, 2007 Just remember you need to escape quotes inside a string or use single quotes so this should work:$text = '<?php echo("hi dude"); $_SESSION["hello"]="Hi"; ?>'; Quote Link to comment Share on other sites More sharing options...
zfred09 Posted January 12, 2007 Author Share Posted January 12, 2007 I get string errors in the new file in places such as this because the quote after the echo should be a ' but I had to change it or the write file would error out[code]echo("<form method="post" action="auth.php"><p>Username: <input type="text" name="userid" id="myform" maxlength="20" size="12"/></p> <p>Password : <input type="password" name="userp" id="myform" maxlength="20" size="12"/></p> <input type="submit" value="Login" class="gobutton"/></font> </form>");[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 Every time you have a " inside a string with a ", you have to escape it. You're still not doing that. If you want to always use " use this: \"echo("<form method=\"post\" Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 12, 2007 Share Posted January 12, 2007 It won't error and you can keep everything the same as long as: * You remeber not to include the type of quote (" or ') that surrounds a string in that string without escaping it:[b]\"[/b] or [b]\'[/b] Quote Link to comment Share on other sites More sharing options...
zfred09 Posted January 12, 2007 Author Share Posted January 12, 2007 Ah yes that works, I didn't understand/know what escaping the quotes was so thanks for the explanation. Problem Solved. Quote Link to comment 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.