How to replace placeholders with actual values?

后端 未结 6 973
逝去的感伤
逝去的感伤 2021-01-07 12:00

I need a function that replace every variable_name inside \'{}\' with the correct variable. Something like this:

$data[\"name\"] = \"Johnny\";
$data[\"age\"         


        
6条回答
  •  感动是毒
    2021-01-07 13:03

    You can try out vsprintf it has slightly different syntax

    $string = 'hello my name is %s and I am %d years old';
    
    $params = array('John', 29);
    
    var_dump(vsprintf($string, $params));
    //string(43) "hello my name is John and I am 29 years old" 
    

提交回复
热议问题