- preg_replace_callback: documentation ( source)
<?php
$selfTable = 'songs';
$tables = array(
'types' => 'layout_template_types'
);
$string = '$content AS content,
CONCAT_WS(
".",
$types.alias,
layout_templates.custom_item_id
),
id';
echo preg_replace_callback('#\$([\w]+)\.([\w]+)#', function($match) use ($tables) {
return '`' . $tables[$match[1]] . '`.`' . $match[2] . '`';
}, $string);