Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
share|improve this question
2  
You could combine them, but that won't make your code any better. You don't even need 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.