1 2 3 4 5 6 7 8 9
<?php $string = "string_key::%foo%:%bar%"; $params = array("foo" => 1, "bar" => 2); foreach($params as $key => $value) { $search[] = "%" . $key . "%"; $replace[] = $value; } $output = str_replace($search, $replace, $string); echo $output;
1
string_key::1:2