I have an array that contains possible request URIs. Some of the array values could contain comma delimited URIs:
array(
0 => 'GET /, GET /something',
1 => 'GET /login',
2 => 'GET /user/profile',
)
Let’s say I want to find the key that contains “GET /something”. How can I use preg_grep to do this? Currently, I’m trying this:
preg_grep('/(.*)GET \\'.$uri.'(.*)/', $array);
However, I just get an empty array back. Any idea what I’m doing wrong?
Rather than having $uri in your string for preg_grep, concat it into a $pattern var first (for ease of reading mostly plus you can echo it and check as the above comment suggested):
As to answer your question specifically, you escaped the wrong type of slash :p