开发者

php preg_replace subpattern

I would like to highlight the last slug in url like this:

http://www.domain.org/school.html

Here's the pattern to capture the开发者_运维百科 slug:

$pattern = "/\/([^/]+)\.html$/";

How do I run preg_replace on url to replace the slug with <b>slug</b>?


You need to preserve the / and filename suffix then for replacement:

= preg_replace("~(/)([^/]+)(\.html)$~", "$1<b>$2</b>$3", $urltext);


Just simple as this - see examples on php site

preg_replace( $pattern, "<b>\$1</b>", $input );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜