Sesquipedalian Posted December 30, 2007 Share Posted December 30, 2007 hey everyone, I am making something, and in it I am writing to a file.. $content is the name of the variable that i am writing, but it is also something that is supposed to be in the file... The problem is, it gets rid of the $content in the file for some reason, when it's written like this: $content = "<? $content = '".$_POST['content']."'; include ('../login/login.php'); ?>"; I am writing it like that for situations when there are " in $_POST['content']. I have another code for when there isn't, so that ' can be written... That code seems to actually put $content as well, but the only difference is that " and ' are opposite to what they are in the code before.. $content = '<? $content = "'.$_POST['content'].'"; include ("../login/login.php"); ?>'; So.. why does the second one work, but the other one doesn't? Quote Link to comment https://forums.phpfreaks.com/topic/83675-solved-why-wont-it-write-content/ Share on other sites More sharing options...
kenrbnsn Posted December 30, 2007 Share Posted December 30, 2007 Variables are evaluated when enclosed in double quotes, but not when enclosed in single quotes. The first code snippet: <?php $content = "<? $content = '".$_POST['content']."'; include ('../login/login.php'); ?>"; ?> surrounds the variable $content in double quotes so the value of that variable is put into the string. In the second snippet: <?php $content = '<? $content = "'.$_POST['content'].'"; include ("../login/login.php"); ?>'; ?> uses single quotes, so the string $content is treated as a literal. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83675-solved-why-wont-it-write-content/#findComment-425698 Share on other sites More sharing options...
Sesquipedalian Posted December 30, 2007 Author Share Posted December 30, 2007 Ah. Okay, thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/83675-solved-why-wont-it-write-content/#findComment-425718 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.