Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php代码中使用php include_Php - Fatal编程技术网

在php代码中使用php include

在php代码中使用php include,php,Php,我有一个php代码,将创建一个txt文件,我的问题是添加的是txt文件的内容 我想从外部文件中包含它 这是我迄今为止使用的代码: <?php $data = $_POST; $time = time(); $filename_prefix = 'file/evidence_file'; $filename_extn = 'txt'; $filename = $filename_prefix.'-'.$time.'-'.uniqid().'.'.$filename_extn; if(

我有一个php代码,将创建一个txt文件,我的问题是添加的是txt文件的内容

我想从外部文件中包含它

这是我迄今为止使用的代码:

<?php
$data = $_POST;
$time = time();
$filename_prefix = 'file/evidence_file';
$filename_extn   = 'txt';

$filename = $filename_prefix.'-'.$time.'-'.uniqid().'.'.$filename_extn;

if( file_exists( $filename ) ){
 # EXTREMELY UNLIKELY, unless two forms with the same content and at the same time are submitted
  $filename = $filename_prefix.'-'.$time.'-'.uniqid().'-'.uniqid().'.'.$filename_extn;
 # IMPROBABLE that this will clash now...
}

if( file_exists( $filename ) ){
 # Handle the Error Condition
}else{
  file_put_contents( $filename , '<?php include("text.php"); ?>' );
}
?>

问题是在当前代码中使用php包含!它在txt文件中打印的内容如下:

<?php include("text.php"); ?>

如何让它显示text.php的内容

text.php文件还包含php代码。

使用函数而不是include

file_put_contents($filename, file_get_contents("text.php"));
如果希望执行包含的代码,而不是将其用作文本,请使用
include

使用函数而不是include

file_put_contents($filename, file_get_contents("text.php"));
如果希望执行包含的代码,而不是将其用作文本,请使用
include

使用函数而不是include

file_put_contents($filename, file_get_contents("text.php"));
如果希望执行包含的代码,而不是将其用作文本,请使用
include

使用函数而不是include

file_put_contents($filename, file_get_contents("text.php"));

当您希望执行包含的代码而不是将其用作文本时,请使用
include

目前,您只需将一个字符串放入,因此它将按照字面上的意思执行,
include()
无论如何都不是您想要的

include(“text.php”)加载php文件并在放入php时执行其内容,我认为您不想这样做。使用
file\u get\u contents()
代替,如下所示:

file_put_contents($filename,file_get_contents("text.php"));

目前,您只需在中输入一个字符串,因此它将接受您输入的内容,而且无论如何,
include()
不是您想要的内容

include(“text.php”)加载php文件并在放入php时执行其内容,我认为您不想这样做。使用
file\u get\u contents()
代替,如下所示:

file_put_contents($filename,file_get_contents("text.php"));

目前,您只需在中输入一个字符串,因此它将接受您输入的内容,而且无论如何,
include()
不是您想要的内容

include(“text.php”)加载php文件并在放入php时执行其内容,我认为您不想这样做。使用
file\u get\u contents()
代替,如下所示:

file_put_contents($filename,file_get_contents("text.php"));

目前,您只需在中输入一个字符串,因此它将接受您输入的内容,而且无论如何,
include()
不是您想要的内容

include(“text.php”)加载php文件并在放入php时执行其内容,我认为您不想这样做。使用
file\u get\u contents()
代替,如下所示:

file_put_contents($filename,file_get_contents("text.php"));

我想你应该这样做

file_put_contents( $filename , '<?php '. file_get_contents("text.php") .'?>' );

file\u put\u contents($filename),我想你应该这样做

file_put_contents( $filename , '<?php '. file_get_contents("text.php") .'?>' );

file\u put\u contents($filename),我想你应该这样做

file_put_contents( $filename , '<?php '. file_get_contents("text.php") .'?>' );

file\u put\u contents($filename),我想你应该这样做

file_put_contents( $filename , '<?php '. file_get_contents("text.php") .'?>' );

file\u put\u contents($filename,如上所述,您可以使用file\u get\u content来获取文件的内容

但是,如果您想首先执行文件,因为它是php代码,并获得结果内容,然后放入文件(我想这就是您想要的),那么您必须使用缓冲区:

ob_start();

include('text.php');

$content = ob_get_contents();
ob_end_clean();

file_put_contents($filename , $content);
通过这种方式,执行php文件,并将其结果内容传递给该文件。
如果您想了解有关输出控制功能的更多信息,这里有。

如前所述,您可以使用file\u get\u content来获取文件的内容

但是,如果您想首先执行文件,因为它是php代码,并获得结果内容,然后放入文件(我想这就是您想要的),那么您必须使用缓冲区:

ob_start();

include('text.php');

$content = ob_get_contents();
ob_end_clean();

file_put_contents($filename , $content);
通过这种方式,执行php文件,并将其结果内容传递给该文件。
如果您想了解有关输出控制功能的更多信息,这里有。

如前所述,您可以使用file\u get\u content来获取文件的内容

但是,如果您想首先执行文件,因为它是php代码,并获得结果内容,然后放入文件(我想这就是您想要的),那么您必须使用缓冲区:

ob_start();

include('text.php');

$content = ob_get_contents();
ob_end_clean();

file_put_contents($filename , $content);
通过这种方式,执行php文件,并将其结果内容传递给该文件。
如果您想了解有关输出控制功能的更多信息,这里有。

如前所述,您可以使用file\u get\u content来获取文件的内容

但是,如果您想首先执行文件,因为它是php代码,并获得结果内容,然后放入文件(我想这就是您想要的),那么您必须使用缓冲区:

ob_start();

include('text.php');

$content = ob_get_contents();
ob_end_clean();

file_put_contents($filename , $content);
通过这种方式,执行php文件,并将其结果内容传递给该文件。
如果您想了解更多关于输出控制函数的信息,这里是。

文件\u get\u contents()而不是include()是否也要执行php文件?文件\u get\u contents()而不是include()是否也要执行php文件?文件\u get\u contents()而不是include()是否也要执行php文件?文件\u get\u contents()除了include()之外,您还想执行php文件吗?您应该添加代码来解释如何使用
文件\u get\u contents
(以及说明),也许可以解释为什么在这个用例场景中
include
不合适,否则这更多的是一个注释而不是一个答案。编辑:更好您应该添加代码来解释如何使用
file\u get\u contents
(以及解释),也许可以解释为什么在这个用例场景中
include
不合适,否则这更多的是一个注释而不是一个答案。编辑:更好您应该添加代码来解释如何使用
file\u get\u contents
(以及解释),也许可以解释为什么在这个用例场景中
include
不合适,否则这更多的是一个注释而不是一个答案。编辑:更好您应该添加代码来解释如何使用
file\u get\u contents
(以及解释),也许可以解释为什么
include
在这个用例场景中不合适,否则这更多的是注释而不是答案。编辑:更好