Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有如下所示的字符串:
当它们出现在两个数字之间时,我想替换任何出现的/,,和a 。\所以上面的一切最终都会看起来像3\2 Johns St. 使用 PHP 执行此操作的最简单方法是什么?
/
,
\
3\2 Johns St
利用preg_replace('/(\d)[\/, ](\d)/', '$1\\\\$2', $string);
preg_replace('/(\d)[\/, ](\d)/', '$1\\\\$2', $string);
尝试这个 :
$str = '3/2 Johns St'; echo $str_new = preg_replace('/(\d)([^\d])+(\d)/','$1\\\\$3',$str);