在PHP中使用preg_match来捕获带有regex组的命名子模式

88 阅读1分钟

你可以使用下面的例子,通过使用preg_match 函数将数值分割成命名的数组键。

输入

你需要将其压扁。

{

模式

/^{"time_local":"(?.*?)","client_ip":"(?.*?)","remote_addr":"(?.*?)","remote_user":"(?.*?)","request":"(?.*?)","status":"(?.*?)","body_bytes_sent":"(?.*?)","request_time":"(?.*?)","http_referrer":"(?.*?)","http_user_agent":"(?.*?)","request_id":"(?.*?)"}$/

测试

preg_match($pattern, $input, $matches);

$matches 变量的内容。完整的例子在这里

Array