I've been searching a lot on info about preg_replace_callback and managed to get my thing to work, but I'm wondering if this can be optimized?
Can I run these two in a single preg run?
// 1. replace [date xx] with event date in "xx" dateformat
$output = preg_replace_callback('/\[date (.*?)]/', function($matches) use($eventDate)
{
return date($matches[1],$eventDate);
}, $output);
// 2. replace [title], [venue] and [link]
$replacePattern = array( '/\[title\]/',
'/\[venue\]/',
'/\[link\]/');
$replaceReplacement = array($eventTitle, $eventVenue, $eventLink);
$output = preg_replace($replacePattern, $replaceReplacement, $output);
preg_replace()
to do the latter...str_replace()
works just as well and is a way better choice. – Till Helge Mar 4 '13 at 11:33