Answers for "php replace all text from string with associate array values"

PHP
0

php replace all text from string with associate array values

$string = 'This is a nice section';
$replaceable = [
  'section' => 'house'
];

foreach ($replaceable  as $key => $value) {
	$string = preg_replace("/(" . $key . ")/", $value, $string);
}

var_dump($string);
Posted by: Guest on January-23-2022

Code answers related to "php replace all text from string with associate array values"

Browse Popular Code Answers by Language