Php 如何替换。。。在一个单词之间,一部分是数字,另一部分是';智力?

Php 如何替换。。。在一个单词之间,一部分是数字,另一部分是';智力?,php,string,replace,Php,String,Replace,如果一个单词的一部分是数字,另一部分是int,我怎么能在单词之间加一个空格呢?像这样: $string = "this is a 2000px height photo"; $string = preg_replace('???',' //1',$string); echo $string; //this is a 2000 px height photo 有人能帮我吗?谢谢 $string = preg_replace('/(\d+)([[:alpha:]]+)/', '$1 $2', $s

如果一个单词的一部分是数字,另一部分是int,我怎么能在单词之间加一个空格呢?像这样:

$string = "this is a 2000px height photo";
$string = preg_replace('???',' //1',$string);
echo $string; //this is a 2000 px height photo
有人能帮我吗?谢谢

$string = preg_replace('/(\d+)([[:alpha:]]+)/', '$1 $2', $string);
  • \d+
    匹配任何数字
  • [[:alpha:]+
    匹配任何字母(
    \w+
    是错误的,因为匹配字母和数字:
    preg_replace()
    调用拆分数字-例如,“100”变为“10 0”)

这很好..但不知何故,这也会分割单个数字(例如:“10张图像2000px高度照片”您会看到:“10张图像2000px高度照片”)