Hi I've been trying to achieve this code but it doesn't work at all. Here's the code: $link = '<a href = 'home.php' class="[home.php]">home</a>'; From the link above, I try to replace the [home.php] with my class name "active". I try this code: preg_replace('/\[*\]/', 'active', $link); But that code was not work at all, any idea? Thanks
class name is never kept with .php it should be $link = '<a href = 'home.php' class="[home]">home</a>';
I prefer not using the . unless absolutely necessary. the last solution would fail if there were two [home.php] links for example in the same text Use this instead $pattern = '/\[[^\]]+\]/'; PHP: