在输出中获取php作为文本 [英] getting php as text on output
问题描述
\
将其插入到PHP中,但是如何在代码中完成这样的操作? <?php
$ stringData =
//从这里开始
<?php
$ width = $ _GET ['width'];
$ heigh = $ _GET ['height'];
echo'你好';
?>
//到此为止
;
?>
我已经标记了那部分,我希望将它作为文本输出,但是当我在页面上放置它时,我得到的语法错误不确定原因。
编辑#2
下面是我的完整代码,我解释了我的代码是如何工作的以及为什么。
我的代码是创建页面并将内容放入创建页面
< form method =post>
< label>页面名称:< / label>< br>
< input>'text'name ='filename'placeholder ='page name'>
< label>文件夹< / label>
< ;选择name =thisfolder>
< / option>
< / option>
< / option>
< option value =>默认< < option value =Folder2> Folder2< / option>
< option value =Folder3> Folder3< / option>
< / gt>< br>< br> ;
<标签>&内容LT; /标签><峰; br>
< input type ='text'name ='strin'placeholder ='创建页面的内容'>
< input type ='submit'value ='Add Feed'>
< / form>
<?php
if($ _SERVER [REQUEST_METHOD] ==POST)
{
//要创建的文件的名称
$ filename = $ _ POST ['filename'];
//创建页面的文件的名称
$ strin = $ _ POST ['strin'];
//将$ filename放入
$文件夹的名称thisFolder = $ _POST ['thisfolder'];
//确保#thisFolder实际上是一个文件夹
if(!is_dir(__ DIR __。'/'。$ thisFolder)){
//如果不是,我们需要创建一个新文件夹
mkdir(__ DIR __。'/'。$ thisFolder);
}
//。 。 。 / [文件夹名称] /页面[文件名称] .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);
}
?>
我想要做的是,传递位于 $ stringData
到将要创建的页面
您需要转义 $
在您的文本中。
设置 $ stringData
这:
$ stringData =
//从这里开始
<?php
\ $ width = \ $ _GET ['width'];
\ $ heigh = \ $ _GET ['height'];
echo'Hello';
?>
//在此结束
;
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
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
";
这篇关于在输出中获取php作为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!