Reputation: 11579
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>
?
Upvotes: 1
Views: 1846
Reputation: 145512
You need to preserve the / and filename suffix then for replacement:
= preg_replace("~(/)([^/]+)(\.html)$~", "$1<b>$2</b>$3", $urltext);
Upvotes: 2
Reputation: 11779
Just simple as this - see examples on php site
preg_replace( $pattern, "<b>\$1</b>", $input );
Upvotes: 0