title: PHP preg_replace: Deprecated
body: <p>I have this Deprecated warning after switching my php to 5.5.8,</p>
  
  <blockquote>
    <p>Deprecated:  preg_replace(): The /e modifier is deprecated, use
    preg_replace_callback instead in <b>C:\wamp\www...Curly.php</b> on
    line <b>28</b><br /></p>
  </blockquote>
  
  <p>This is the function in my class of <code>Curly</code>,</p>
  
  <pre><code>public function replace ($input, $options = array()) {
  
          return preg_replace("/\{{2}(([a-z\_]+\|.+)|([a-z\_]+))\}{2}/Ue",'$this-&gt;_replace("\\1",$options)',$input);
      }
  </code></pre>
  
  <p>so if I use <code>preg_replace_callback</code> instead,</p>
  
  <pre><code>return preg_replace_callback("/\{{2}(([a-z\_]+\|.+)|([a-z\_]+))\}{2}/Ue",'$this-&gt;_replace("\\1",$options)',$input);
  </code></pre>
  
  <p>Then I get this error,</p>
  
  <blockquote>
    <p><b>Warning</b>:  preg_replace_callback(): Requires argument 2,
    '$this-&gt;_replace(&quot;\1&quot;,$options)', to be a valid callback
    in <b>C:\wamp\www...Curly.php</b> on line <b>28</b><br /></p>
  </blockquote>
  
  <p>Any ideas how can I fix this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>class Curly extends CoreModel
  {
      // Set the property/ variable of this class
      public $constant = null;
  
      /**
       * Extend the parent class property.
       */ 
      public function __construct($connection){
  
         // Extend parent's.
         parent::__construct($connection);
         $this-&gt;constant = new Constant($connection);
      }
  
      /**
       * Replace the curly in an input string
       * @param string $input
       * @return string
       */
      public function replace ($input, $options = array()) {
  
          //return preg_replace("/\{{2}([a-z]+\|.+)\}{2}/Ue",'$this-&gt;_replace("\\1")',$input);
          //return preg_replace("/\{{2}(([a-z\_]+\|.+)|([a-z\_]+))\}{2}/Ue",'$this-&gt;_replace("\\1",$options)',$input);
          return preg_replace_callback(
              "/\{\{([a-z_]+(?:\|.+)?)\}\}/U",
              function($m) { return $this-&gt;_replace($m[1], $options); }, 
              $input
          );
      }
  
      /**
       * Run the replacement code on a given macro string
       * @param string $input
       * @return string
       */
      private function _replace ($input,$options) {
  
          // Set local vars.
          $defaults = array();
  
          // Call internal method to process the array.
          $array = parent::arrayMergeValues($defaults,$options);
          //print_r($array);
  
          // Convert array to object.
          $property = parent::arrayToObject($array);
  
          // type-checking comparison operator is necessary.
          if (strpos($input, '|') !== false) { 
  
              //VERTICAL SIGN FOUND
              list ($name,$params) = explode("|",$input);
  
              if (method_exists($this,$name)) {
                  return $this-&gt;$name($params);
              }
              throw new Exception ("Unrecognised macro: {$name}.",500);
  
          } else {
  
              // Get the input string and request the data from constant table.
              $value = $this-&gt;constant-&gt;getRow($input)-&gt;value;
  
              // If there is a value returned from the contstant table.
              if($value !== null) { 
  
                  // Return the what is returned from the the constant table.
                  return $value;
  
              } else if(isset($property-&gt;$input)) { // If there is a customised value from the developer.
  
                  // Return what is customised by the developer.
                  return $property-&gt;$input;
  
              } else { // Nothing is found.
  
                  // Return what is from the input.
                  return "{{{$input}}}"; 
  
              }
  
          }   
      }
  
      /**
       * Replaces a YouTube curly
       * @param string $params
       * @return string
       */
      private function youtube ($params) {
  
          parse_str($params);
  
          // set defaults
          if (!isset($id)) { $id = "ykwqXuMPsoc"; }
          if (!isset($width)) { $width = 560; }
          if (!isset($height)) { $height = 315; }
  
          // output the final HTML
          return "&lt;iframe width=\"{$width}\" height=\"{$height}\" src=\"http://www.youtube.com/embed/{$id}\" frameborder=\"0\" allowfullscreen&gt;&lt;/iframe&gt;";
      }
  }
  </code></pre>