Mm Pp Mm Pp -4 years ago 108
HTML Question

getting php as text on output

first of all this is my php code. i am trying to get this code as text on output. not sure how i do that. with html we can do

\"
to insert it inside php but how do i get this done like that on my code ?

<?php
$stringData = "

// Start here

<?php
$width = $_GET['width'];
$heigh = $_GET['height'];

echo 'Hello';

?>
// End here

";
?>


i have marked that part that i want to get it on output as text but when i put it like that on page i get syntax error not sure why.

EDIT #2

here below is my full code and i explain how my code works and for what.
my code is to create page and put something inside that page created

<form method="post">
<label>Page Name:</label><br>
<input type='text' name='filename' placeholder='page name'>
<label>Folders</label>
<select name="thisfolder">
<option value="">Default</option>
<option value="Folder1">Folder1</option>
<option value="Folder2">Folder2</option>
<option value="Folder3">Folder3</option>
</select><br><br>
<label>content</label><br>
<input type='text' name='strin' placeholder='content of created page'>
<input type='submit' value='Add Feed'>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// the name of the file to create
$filename=$_POST['filename'];
// the name of the file to be in page created
$strin=$_POST['strin'];
// the name of the folder to put $filename in
$thisFolder = $_POST['thisfolder'];
// make sure #thisFolder of actually a folder
if (!is_dir(__DIR__.'/'.$thisFolder)) {
// if not, we need to make a new folder
mkdir(__DIR__.'/'.$thisFolder);
}
// . . . /[folder name]/page[file name].php
$myFile = __DIR__.'/'.$thisFolder. "/page" .$filename.".php";
$fh = fopen($myFile, 'w');
$stringData = "

<?php
$width = $_GET['width'];
$heigh = $_GET['height'];

echo '';

?>

";

fwrite($fh, $stringData);
fclose($fh);
}
?>


what i am trying to do is, passing that php code that is inside
$stringData
to that page that will be created

Answer Source

You'll want to escape the $'s in your text.

Set $stringData like this:

$stringData = "

// Start here

<?php
\$width = \$_GET['width'];
\$heigh = \$_GET['height'];

    echo 'Hello';

?>
// End here

";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download