I have some code like this, which replaces some shortcodes with a link:
$search = array(
'#\{r\|([^|]+)\|([^}]+)\}#',
'#\{t\|([^|]+)\|([^}]+)\}#',
...,
);
$replace = array(
'<a href="/ref/$1">$2</a>',
'<a href="/type/$1">$2</a>',
...,
);
$content = preg_replace( $search, $replace, $content );
I have lots more that are similar so I was wondering, is there some way to reduce this to one simple preg_replace
with a conditional?
For example, use the regex #\{([a-z])\|([^|]+)\|([^}]+)\}#
and replace the first match with something different (r=ref, t=type) based on its letter? (If it helps, the shortcodes are like {r|url-slug|LinkTitle}
.)