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 );
精彩评论