- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
<?php
$text = ['My Name ## is "#P_NAM3#" and \r\n', 'I am \'#P_AG2#\' years old `#abc#`'];
//$r = '#(?P<name>.*?)#';
//$r = '#(\w*)#';
function trad($v) {
var_dump($v);
if($v[1] == '' || $v[1] == 'abc')
return $v[1] . '_es';
return $v[1];
}
var_dump(preg_replace_callback('/#([^#]*)#/m', 'trad', $text));