Search code examples
phpfwrite

Display php code with fwrite inside a php file


Hello i am using the code bellow to write the following line inside a .php file.

$stringDatar = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML+RDFa 1.0//EN'\n";
fwrite($handler, $stringDatar);

I am trying to do the same to write inside a php file with the following code but it doesn't wite the php code.

$stringDatar = "'.<?php $_GET['p']\n.'";
fwrite($handler, $stringDatar);

Any ideas?


Solution

  • Variables are expanded inside double quotes, so it's putting the value of $_GET['p'] into the file. You need to escape the dollar sign so it will be written literally.

    $stringDatar = "'.<?php \$_GET['p']\n.'";