Isabell Isabell - 2 months ago 5x
PHP Question

find word/string in string , do I need regex?

I got following String:

... 12:32 +0304] "GET /test.php?param=value ....

I want to extract the test.php out of this String. I tried to find a php function wich could do this but there was nothing helpful. So my next guess was, what about regex and I tried for so long to get the part between GET / and ?. I failed badly... Does a function in php exists wich could help me out or do I need regex for this? If I do so, how can I get a string out of a string? Important, I don't want to know if test.php is in the string. I want to get everything between GET / and ?.

Thanks a lot


The regex extracting anything between GET / and ? in a capture group:

GET \/(.*?)\?


In PHP it can be used like this:

$str = '... 12:32 +0304] "GET /test.php?param=value ....';
preg_match('/GET \/(.*?)\?/', $str, $re);