开发者

preg_replace removes second backslash at start of line

Consider this:

$sServerPath = "\\\\nlyehvedw1cl016\\projects$\\ARCLE_SW_SVN\\";
$sSVNParentPath = $sServerPath."svn\\";

$bla = "
authz_module_name = TEST_TestRepos
repository_dir = bla

W";
$sSVNParentPath = $sServerPath."sv开发者_运维百科n\\";
$sReplaceBy =  "repository_dir = ".$sSVNParentPath.$sProjectName."\n";
echo $sReplaceBy;
echo preg_replace ('/repository_dir = ([a-zA-Z0-9\/].*?)\n/i', $sReplaceBy, $bla);

The result is:

repository_dir = \\nlyehvedw1cl016\projects$\ARCLE_SW_SVN\svn\

authz_module_name = TEST_TestRepos
repository_dir = \nlyehvedw1cl016\projects$\ARCLE_SW_SVN\svn\

W

The echo of $sReplaceBy shows the resulting string as I expect it, including the first 2 back-slashes.

However, after the preg_replace, the echo of the result shows only one back-slash!

Anybody know what's causing this?


From PHP docs:

To use backslash in replacement, it must be doubled ("\\" PHP string).

Since your replacement doesn't contain quotes, you can simply use addslashes():

echo preg_replace ('/repository_dir = ([a-zA-Z0-9\/].*?)\n/i', addslashes($sReplaceBy), $bla);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜