Jump to content

[SOLVED] why won't it write $content?


Sesquipedalian

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/83675-solved-why-wont-it-write-content/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.