PHP正则替换问题?


$s = 'thearea:北京/北京市/石景山区:9';
如何用用一个preg_replace 函数将上面的字符串替换成 北京/北京市/石景山区 ?

正则表达式 php

天真真是无邪 9 years, 7 months ago

 <?php
$s = 'thearea:北京/北京市/石景山区:9';

preg_match('/:(.+?):/', $s, $out);

var_export($out[1]);

银白的gouf answered 9 years, 7 months ago

http://3v4l.org/0Aegc 不过说实话你这个需求是不是用 preg_match_all 或者 explode 之类的好做一点?

不器用なグルメ answered 9 years, 7 months ago

Your Answer