I’ve written this regex code,
/.[^.]*$/ -> file extension
/\?.*/ -> removes everything ?paramternames in PHP
Current usage:
preg_replace('/\?.*/', '', preg_replace('/.[^.]*$/','',basename($_SERVER['REQUEST_URI'])))
How can I make it to a single preg_replace call, instead of these two, is there a way to merge the two RegExes into one single RegEx which does the job?
Can I posted expected output result? Yes.
http://localhost/books.php?tab=to_read
when I run this PHP code with two preg_replaces, I get "books", which I use to highlight in the menu to tell the user current page and menu highlight based on the page URI.
EDIT: There's nothing wrong with this code, it works. However, I want to merge the two regexes into one and only invoke one preg_replace.
preg_replace('/.[^.]*$/','',basename($_SERVER['REQUEST_URI']));?