J
J
Jony13372016-05-06 13:07:43
PHP
Jony1337, 2016-05-06 13:07:43

PHP creates php how to do it?

Hello everyone
today I tried to create a php file using php
Let's say there is such a php code

$nD = "index";
$nS = "example";
$html = <<<HERE
<?php
$y = rand(1, 9) ; 
?>
<html>
<head>
<title>Master</title>
<script>
setTimeout( 'location="http://site.ru/maps/$nD.php?id=<? echo $y;?>";', 100 );
</script>

</head>
<body>
</body>
</html>
HERE;
$var = "$html";
  $f = fopen("maps/$nS.php","w+");
  fwrite($f,$var); 
  fclose($f);

and this is what file is created
<?php
 = rand(1, 9) ; 
?>

<html>
<head>
<title>Master</title>
<script>
setTimeout( 'location="http://site.ru/maps/example.php?y=<? echo ;?>";', 100 );
</script>

</head>
<body>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Kryvel, 2016-05-06
@Jony1337

Perhaps in your case it would be better to use NOWDOC instead of HEREDOC,
here you can read about it
php.net/manual/en/language.types.string.php#langua...
php.net/manual/en/language.types.string .php#langua...
well, or escape the $ sign for proper parsing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question