I'm trying to rewrite this function
<?php
$vars = array('id'=>$_SESSION['id'], 'name' => $_SESSION['username'],
'time' => $time->format('Y-m-d H:i:s');
$filename = "@name - @time";
echo preg_replace('/@(\w+)/e', '$vars["$1"]', $filename);
?>
So far, this is where I got
<?php
$vars = array('id'=>$_SESSION['id'], 'name' => $_SESSION['username'],
'time' => $time->format('Y-m-d H:i:s');
$filename = "@name - @time";
echo preg_replace_callback('/@(\w+)/', function ($matches) {return '$vars["$1"]';}, $filename);
?>
But this only shows me $vars["$1"] - $vars["$1"]
, so I'm obviously doing something wrong. Even after reading the documentation I don't really understand what I'm doing. Can anyone help me out?