搜尋

首頁  >  問答  >  主體

正则表达式 - PHP正则替换问题?

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

PHP中文网PHP中文网2928 天前289

全部回覆(2)我來回復

  • 迷茫

    迷茫2017-04-10 15:11:08

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

    回覆
    0
  • PHP中文网

    PHP中文网2017-04-10 15:11:08

    <?php
    $s = 'thearea:北京/北京市/石景山区:9';
    
    preg_match('/:(.+?):/', $s, $out);
    
    var_export($out[1]);
    

    回覆
    0
  • 取消回覆