So I’m working on a project that will take a saved configuration from a MariaDB server and parse it though PHP, creating a readable array with a key value relationship, here’s the current data from the database:
item1=value1
item2=value2
item3=value3
item4=value4
item5=value5
item6=value6
item7=value7
item8=value8
item9=value9
Now, I can get these values from the database fine. But what I want to do is take each of these values is set the value before the equal sign (=) as they key, and the value after is as the value. I also need it to ignore or not display certain values, like
item10=value10
item11=value11
item12=value12
Here is the code I am currently playing with:
[php]
foreach($stmt->fetchAll() as $k=>$v) {
// this sanitizes the configuration file so all un
// $v['savedconfig] is data coming from db
$allsettings = $v['savedconfig'];
$settings = explode(' ', $allsettings);
//$settings = explode('=', $allsettings);
print_r($settings);
}
[/php]
Needless to say, this code is returning everything and while it does split at the = sign, it keeps newline and spaces in the array instead of splitting them into a new key. I’ve used numerous resources including StackOverlow and links I’ve found here (including a code another developer wrote for me on a separate project that was modified to work with this) and they all return errors, so I’m out of ideas.
Any help to get me pointed in the right direction would be greatly appreciated.