Php 使用preg_replace从文件中删除行

Php 使用preg_replace从文件中删除行,php,Php,我想从配置文件中删除这一行 line :define('APP_MAIL_FROM_EMAIL_NAME','example'); 这是我的密码 <?php $configFileContents = file_get_contents('config.php'); if (!empty($configFileContents)) { if (strstr($configFileContents, 'define(\'APP_MAIL_FROM_EMAIL_NA

我想从配置文件中删除这一行

line :define('APP_MAIL_FROM_EMAIL_NAME','example');
这是我的密码

<?php
$configFileContents = file_get_contents('config.php');
if (!empty($configFileContents)) {

            if (strstr($configFileContents, 'define(\'APP_MAIL_FROM_EMAIL_NAME\',')) {
            $configFileContents = preg_replace('/define\(\'APP_MAIL_FROM_EMAIL_NAME.*\R/', '', $configFileContents);
            }
            file_put_contents("config.php", $configFileContents);
        }   
?>
如果
APP\u MAIL\u FROM\u EMAIL\u NAME'、
和逗号之间存在空格,则其不起作用
有什么问题需要做任何更改什么???

试试这个,它将包括角色之间的所有空格

preg_replace('/define\(\'APP_MAIL_FROM_EMAIL_NAME.s+*\R/', '', $configFileContents);

从正则表达式中删除
\R
,或者使其成为可选,即使我删除了\R不工作。而且它只删除内容,而不删除整个内容
preg_replace('/define\(\'APP_MAIL_FROM_EMAIL_NAME.s+*\R/', '', $configFileContents);