开发者

php preg_replace subpattern

开发者 https://www.devze.com 2023-03-12 01:06 出处:网络
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:

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

精彩评论

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