php - get content from second pair of quotes in string

Posted by Aaron Turecki on Stack Overflow See other posts from Stack Overflow or by Aaron Turecki
Published on 2014-06-09T15:15:01Z Indexed on 2014/06/09 15:25 UTC
Read the original article Hit count: 254

Filed under:
|
|

I'm trying to get the contents of the second quotes and only the second quotes from a string. Right now I'm able to get the contents of all three quotes. What am I doing wrong? Is it possible to just print the second value in the output array?

Text

2014-06-02 11:48:41.519 -0700   Information 94  NICOLE  Client "[WebDirect] (207.230.229.204) [207.230.229.204]" opening database "FMServer_Sample" as "Admin".

PHP

if (preg_match_all('~(["\'])([^"\']+)\1~', $line, $matches))
                $database_names = $matches[2];

print_r($database);

Output

[WebDirect] (207.230.229.204) [207.230.229.204], FMServer_Sample, Admin

© Stack Overflow or respective owner

Related posts about php

Related posts about regex