Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.