I have a .h file which contains hundred of lines code. I want to get back the strings from the variable.
string PackageToRun[][] = { {"M16.1","M16.1EP1","M16.2","M17"},
{"Tv16.2","Tv17","Ta17","Ta16.2 MOpenTAS","Tv17.1","Ta17.1","T16.2","T16.2c"} };
Is it possible to write a Regex in PHP which get back "M16.1","M16.1EP1" ... ?! If it's possible, will it work if I'm adding more string to PackageToRun ?!
Hey that sort of looks like JSON!
<?php
$file = '
string PackageToRun[][] = { {"M16.1","M16.1EP1","M16.2","M17"},
{"Tv16.2","Tv17","Ta17","Ta16.2 MOpenTAS","Tv17.1","Ta17.1","T16.2","T16.2c"} };
';
if( preg_match('#string PackageToRun\[\]\[\] = ({.*});#is', $file, $matches)) {
$data = json_decode(str_replace(array('{','}'), array('[',']'), $matches[1]));
print_r($data);
}
Output:
Array (
[0] => Array (
[0] => M16.1 [1] => M16.1EP1 [2] => M16.2 [3] => M17
)
[1] => Array (
[0] => Tv16.2 [1] => Tv17 [2] => Ta17 [3] => Ta16.2 MOpenTAS
[4] => Tv17.1 [5] => Ta17.1 [6] => T16.2 [7] => T16.2c
)
)