The solution is specific to OP question. There are much better solution available.
If you want output as 123
:
function show($text) {
$find = array(
'/{asd}/',
);
return preg_replace($find,'123',$text);
}
$text = "{asd}";
$htmltext = show($text);
echo $htmltext;
If you want output as {123}
:
function show($text) {
$find = array(
'/asd/',
);
return preg_replace($find,'123',$text);
}
$text = "{asd}";
$htmltext = show($text);
echo $htmltext;
Check example #2 in preg_replace for how to use array as parameters.
Example #2 Using indexed arrays with preg_replace()
<?php
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);
?>
The above example will output:
The bear black slow jumped over the lazy dog.
By ksorting patterns and replacements, we should get what we wanted.
<?php
ksort($patterns);
ksort($replacements);
echo preg_replace($patterns, $replacements, $string);
?>
The above example will output:
The slow black bear jumped over the lazy dog.