I have a script that is watching the last line of a log file in real time. When the following line appears. I want to extract the data inside the second set of brackets. My original code worked fine, problem is that the log output has changed. Sample log output:
2016-04-28 16:54:49 INFO [ADMINCGI sid=1] Title updated [Peezy - Dope Fein Baby (Feat. TID Sweeze & H.N.I.C Pesh)]
2016-04-28 16:54:49 INFO [ADMINCGI sid=1] DJ name updated [1]
I need to first ensure that the line in question line #1 is the line found and then extract the text inside second brackets if possible.
I am using this but it is returning the #2 line
My code:
$line ="2016-04-27 22:56:48 INFO [ADMINCGI sid=1] Title updated [Tessa Feat. Gucci Mane - Get You Right]";
echo $line;
$pattern="/\[([^\]]*)\]/";
$needle = " Title updated ";
if (strpos($line,$needle) !== false) {
preg_match_all($pattern, $line, $matches);
foreach ($matches[1] as $a ){
// echo $a."</br>";
// echo $matches[1][1];
$fulltitle = explode("-", $matches[1][1]);
$artist = $fulltitle[0];
$title = $fulltitle[1];
echo $artist;
preg_match_all('~\[([^][]*)]~', $input, $m); $my_val = $m[1][1];