Home >Backend Development >PHP Tutorial >正则表达式 - PHP正则替换问题?

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

WBOY
WBOYOriginal
2016-06-06 20:40:511063browse

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

回复内容:

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

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

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

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

var_export($out[1]);
</code></code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn