我在一个文件里有一行 CurrentStatus=`svcs -a | grep $name | awk '{print $1}'` 。
需要替换成CurrentStatus=`svcs -a | grep $name | awk \'{print $1}\'` 用preg_replace怎么写,或者有什么其他办法。
需要替换成CurrentStatus=`svcs -a | grep $name | awk \'{print $1}\'` 用preg_replace怎么写,或者有什么其他办法。
addslashes($string)就可以了。
file_put_contents($filename, file_get_contents($filename));
string addslashes ( string $str )
返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)。 单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)都会在前面加上\
如果仅仅需要替换单引号('),则使用str_repalce
echo str_replace("'","\'",$str);