[英]PHP- replace strings where they appear between two numbers
I have strings that look like the following: 我的字符串如下所示:
I want to replace any occurance of /
, ,
and 我想替换
/
,
和的任何出现 with a
\\
when they appear in between 2 numbers. 当它们出现在2个数字之间时,用
\\
表示。 So the above would all end up looking like 3\\2 Johns St
. 因此,上述所有内容最终看起来像是
3\\2 Johns St
What is the easiest way to do this with PHP? 用PHP做到这一点的最简单方法是什么?
使用preg_replace('/(\\d)[\\/, ](\\d)/', '$1\\\\\\\\$2', $string);
Try this : 尝试这个 :
$str = '3/2 Johns St';
echo $str_new = preg_replace('/(\d)([^\d])+(\d)/','$1\\\\$3',$str);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.