I read in from a text file and assign variables as if they were an array with the list. I do so by exploding on line breaks.
However, I also want to trim any white space on either side of the input. From my understanding and testing that is exactly what trim() does.
I would like to shorten this so that it is less repetitive and easier to read.
$config = file_get_contents('scripts/secure/config.txt');
list($host, $dbname, $username, $password) = explode ("\n", $config);
$host = trim($host);
$dbname = trim($dbname);
$username = trim($username);
$password = trim($password);
I've tried a few different methods but none seem to work. What I have above does work but I'm looking for a one line approach.