title: Alternative to a bunch of preg_replace
body: <p>Currently I have a custom url syntax that I use to save urls from input. Then I use output buffering to fetch the whole document at the end of execution and replace url syntaxes with anchor tags. But I also have an image syntax that converts image links from input to image tags, as well as youtube tags that convert youtube links to embedded videos.</p>
  
  <p>Long story short  </p>
  
  <p><code>[url]http://www.somesite.com/[my site]</code><br>
  becomes<br>
  <code>&lt;a href='http://www.somesite.com/'&gt;my site&lt;/a&gt;</code></p>
  
  <p><code>[img]http://www.somesite.com/image.jpg[/img]</code><br>
  becomes<br>
  <code>&lt;img src='http://www.somesite.com/image.jpg'/&gt;</code></p>
  
  <p>You get the point. It's kind of starting to bother me because I know that <code>preg_replace</code> is known to have an impact on performance and running it multiple times on a roughly 10,000 character long string<br>
  ( average html document length for my site ) is really not good. I would also like to implement auto-embedding for more websites, and using my current algorithm would mean that I will have to add a new <code>preg_replace</code> for each site, which is ridiculous. I'm looking for advice on how to implement this functionality. Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>I think I didn't express myself clear enough. I am looking for a way to match all of my components with a single parse of the document string. For example when you go to buy groceries you don't go picking up tomatoes, bring them home then go again to pick up cucumbers. You do all the things simultaneously, that's what I'm looking for. Thanks!</p>