I have code that parse copypasted mediainfo text and create the array, but I have a problem because in this code $line
needs to be a lower case, otherwise it's not print anything.
How I can make this working with uppercase letters?
If I change this to strtoupper
code not working anymore.
$line = trim(strtolower($line));
If I wanna parse filename it's always lowercase.
Example:
Original:
My.Home.Video.S01.E01.mp4
After parse:
my.home.video.s01.e01.mp4
class Parser {
// Mediainfo
private $regex_section = "/^(?:(?:general|video|audio|text|menu)(?:s#d+?)*)$/i";
public function parse($string)
{
$string = trim($string);
$lines = preg_split("/
|
|
/", $string);
$output = [];
foreach ($lines as $line) {
$line = trim(strtolower($line));
if (preg_match($this->regex_section, $line)) {
$section = $line;
$output[$section] = [];
}
if (isset($section)) {
$output[$section][] = $line;
} else {
$output['general'][] = $line;
}
}
EDIT:
Whole code: https://pastebin.com/MkxSYk1W
If I remove strtolower
from this line $line = trim(strtolower($line));
I got this when I print output. No values.
Array ( [general] => [video] => [audio] => [text] => )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…