2011-11-23 34 views
2

我怎样才能放在一个单词之间的空间,其中一部分是数字另一个是'?像这样:如何替换...其中一个部分是数字而另一个是'int?

$string = "this is a 2000px height photo"; 
$string = preg_replace('???',' //1',$string); 
echo $string; //this is a 2000 px height photo 

有人可以帮助我吗?谢谢!

回答

3
$string = preg_replace('/(\d+)([[:alpha:]]+)/', '$1 $2', $string); 
  • \d+匹配任何数字
  • [[:alpha:]]+匹配任何字母(\w+是错误的,因为匹配字母和数字:在preg_replace()呼叫拆分号码 - 如 '100' 变成'10 0' )
+0

这是很好..但不知何故,这也分裂了sinlge数字(exapmple:“10 images 2000px高度照片”你会得到这个:“1 0 images 2000 px height photo”) – faq

+0

我编辑我的评论 – faq

+0

非常好,只是我在找什么!谢谢接受它 – faq

相关问题