title: Call Function PREG_REPLACE
body: <p>With security and also a deprecated function; what would be the easiest and most secure way to call a function in a find and replace?</p>
  
  <p>There are four find and replace modules which can be inserted within content <code>[album][/album], [img][/img], [youtube][/youtube], or [vimeo][/vimeo]</code>.</p>
  
  <p>Using the function I put together so far Images, YouTube and Vimeo were a no brainer. The Album no so much. I would like to call a function based on parameters that are passed.</p>
  
  <p>I tried altering this function into a <code>preg_replace_callback</code> and that just mocks up everything. Is there any alternatives? </p>
  
  <pre><code>function FormatModules($text) {
      $find = array(
          '~\[album\](.+?)\[/album\]~s',
          '~\[img width=(.*?) height=(.*?) alt=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png))\[/img\]~s',
          '~\[youtube\](.+?)\[/youtube\]~s',
          '~\[vimeo\](.+?)\[/vimeo\]~s'
      );
      $replace = array(
          'GenerateAlbum($1)', // call a PHP function
          '&lt;img src="$4" width="$1" height="$2" alt="$3" /&gt;',
          '&lt;iframe src="http://www.youtube.com/embed/$1"&gt;&lt;/iframe&gt;',
          '&lt;iframe src="https://player.vimeo.com/video/$1"&gt;&lt;/iframe&gt;'
      );
      return preg_replace($find, $replace, $text);
  }
  </code></pre>