Hi all,
I'm pretty new to PHP. So far I know regular expression only from Perl
I've written a perl script which I now want to port to PHP. It works in
PErl, but gives my a headache in PHP.
I have a line like this:
"329:47 InitGame:
\.Admin\xxx\.Website\www.yyy.de\g_gametype\hq\gamename\Call of
Duty\mapname\mp_ship\protocol\..."
I want to get the time at the beginning of the line. Further I need the text
between "gametype\" and "\gamename" ("hq" in this case) and the text
between "mapname\" and "\protocol" ("mp_ship").
The reg ex in Perl looks like this:
if ($line =~
m/(\d+:\d+)[\s]*InitGame:.*?_gametype\\(.*?)\\.*?mapname\\(.*?)\\/) {...
It took me quite long time, to find this ugly construct in PHP:
$match_initGame = '(\d+:\d+)\s*InitGame:.*?_gametype' . preg_quote("\\")
.. '(.*?)' . preg_quote("\\gamename") . '.*?' . preg_quote("\\mapname\\") .
'(.*?)' . preg_quote ("\\");
if (preg_match("/$match_initGame/", $line, $matches ) ) {...
Is there is any better way to solve my problem?
Thanks a lot, Thorsten