如何将php字符串写入另一个文件

时间:2018-05-03 18:18:18

标签: php

我正在尝试将字符串写入新创建的文件,但是当我将其写入新创建的文件时,我看到字符串的值,但实际上我想要的字符串显示为$ id = 15;但我只看到15请有人应该帮助我,我已经在这几个小时了

if (file_exists($file)) {
    $newfile = "../".$low.$row["page_id"].".php";
    $url = "../".$low.$row["page_id"];
    $create = fopen($newfile,"w");

    $addfile = "<?php  include '../page.php'; ?>";
    $write = fwrite($create, $addfile);
    fwrite( $create, "<?php $id = $pid; ?>" );
}

我想要的是在新创建的文件中看到$id = $pid,而是看到它存储的值

1 个答案:

答案 0 :(得分:-1)

尝试替换:

发件人:

fwrite( $create, "<?php $id = $pid; ?>" );

fwrite( $create, '<?php $id = '. $pid .'; ?>' );

可以通过多种方式指定PHP字符串 - 请参阅此链接stackoverflow.com/a/3446286/4111622。

带有变量的双引号字符串将使用变量$name值到字符串结果中。

$name = "cale_b"; 
echo( "My name is $name" ); 
output: "My name is cale_b" 

单引号不会取代它。

echo( 'My name is $name' ); 
output: "My name is $name"