Skip to content
Advertisement

how to extract values from url and match them using preg_match

JavaScript

I have a route array as –

JavaScript

How do I match the the $pathInfo with its corresponding route.

this is how i tried to do it –

JavaScript

the only diff is here I defined the routes as

JavaScript

and was matching the values with the (.*) fields.

Advertisement

Answer

You could transform your route paths into appropriate regular expressions, check $pathInfo against each of them, then return the first one which matches (if any):

JavaScript

Usage:

JavaScript

Demo: https://3v4l.org/DoimK

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement