How to use file_get_contents to open a php file, search for the specified string, and add other content under it in a new line?
淡淡烟草味
淡淡烟草味 2017-06-28 09:23:06
0
3
981

I want to implement a function, because every time the system I use is updated, it will overwrite the piece of code I added myself.
I want to implement this function. If it covers my code, I will open that piece of code. Add it again.

This is this code. If it is covered, I will open this file php file,
framework/bootstrap.inc.php

And search for this part, ['development'] == 1);
The complete thing is like this
define('DEVELOPMENT', $_W['config'] ['setting']['development'] == 1);

If true is returned after search, then a new line is added and a piece of code is appended after it
Like this
After search.

`define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);`
// 追加的代码
define('DEBUG', $_W['config']['setting']['debug'] == 1);
if(DEBUG){
    include ROOT.'/framework/debug.php';
}
淡淡烟草味
淡淡烟草味

reply all(3)
我想大声告诉你

Why not find the problem that some code will be overwritten when updating the code, but solve the problem in this roundabout way?

学霸

Why not

define('DEBUG', $_W['config']['setting']['debug'] == 1);
if(DEBUG) {
    include ROOT.'/framework/debug.php';
}

Create a separate file for this code you added, and then load both the system update file and your file into it

require 'xxxx.php'; // 系统更新会覆盖的文件
require 'bbbb.php'; // 你自己添加的代码

In this way, you don’t have to worry about it being overwritten by the system after updating, and it is much easier to maintain your own code.

Ty80

I agree with the point above. But if you have to do this, you can add a comment to the code you added. Then read the contents of the entire file and use comments to split the file into two strings. Then concatenate your code with the two strings, and finally write it to the file.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template