使用php文件名config.php编辑php文件

时间:2017-10-26 16:39:26

标签: php html

我想在php中创建一个名为config.php的文件,其中包含一些与此类似的字符串:

$this->name = 'Example';

在index.php文件中有一个这样的字符串:

<title><?php echo $this->name; ?></title>

我在另一个网站上看到这个,但我不知道这是如何工作的,有人能帮帮我吗?非常感谢你!

我试试这个:

的config.php

    <?php

final class Settings {
    public static $TRUE = "1", $FALSE = "0";

    public function __construct($connect = true) {
        $this->name = 'Example';
    }


   }
?>

index.php

<html>
<head>
    <title><?php echo $this->name; ?></title>
</head>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您可以从here

中获取参考
$my_file = 'config.php';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
$data = 'This is the data';
fwrite($handle, $data);