<?php $string = 'The ID is \$ID and name is \$name'; $row = [ 'ID'=> 5, 'name' => 'delboy1978uk', ]; function replaceStuff($string, $row) { preg_match_all('#\\$\w+#', $string, $matches); foreach ($matches[0] as $match) { $key = str_replace('$', '', $match); $replace = '\\'.$match; $string = str_replace($replace, $row[$key], $string); } return $string; } echo replaceStuff($string, $row);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`