如何修改字符串以确保美元符号前面有奇数个反斜杠?
<?php
$string = file_get_contents('somefile.txt');
echo($string."\n");
$string=str_replace ('$' , '\$' ,$string);
echo($string."\n");
?>
somefile.txt
$first
\$second
\\$third
\\\$forth
\\\\$fifth
输出
$first
\$second
\\$third
\\\$forth
\\\\$fifth
\$first
\\$second
\\\$third
\\\\$forth
\\\\\$fifth
'...'
)中,你根本不需要转义它。 - arkascha