简体   繁体   English

PHP正则表达式添加带有特殊字符的#ErrorLog

[英]PHP regex to add #ErrorLog with special character

i have to add "#ErrorLog" to this line 我必须在此行添加“ #ErrorLog”

$directivesRegex = '#^ *(ServerAlias|ServerAdmin|DocumentRoot|ServerName|CustomLog) +(.+)$#im';

how can i add it to the code ? 如何将其添加到代码中?

Salmen, Salmen,

You are using # as a delimiter, so you either need to escape the # in the regex, or to change the delimiter. 您将#用作分隔符,因此您需要在正则表达式中转义#或更改分隔符。 Just changing the delimiter in your code with a tilde (~): 只需使用波浪号(〜)更改代码中的定界符即可:

$directivesRegex = '~^ *(ServerAlias|ServerAdmin|DocumentRoot|ServerName|#ErrorLog|CustomLog) +(.+)$~im';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM