0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP7にバージョンアップ時のpreg_replace()エラー

Posted at

前にPHPを7にバージョンアップしたときにSmartyでエラーになった。

エラー内容

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
 in /var/www/php/library/pear/Smarty/Smarty_Compiler.class.php on line 270

preg_replace()はPHP7から廃止になったので、代わりにpreg_replace_callback()を使うように修正する。

元ソース

$source_content = preg_replace($search.'e', "'"
             . $this->_quote_replace($this->left_delimiter) . 'php'
             . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
             . $this->_quote_replace($this->right_delimiter)
             . "'"
             , $source_content);

↓修正後

 $source_content = preg_replace_callback($search
                   , create_function ('$matches', "return '"
                       . $this->_quote_replace($this->left_delimiter) . 'php'
                       . "' . str_repeat(\"\n\", substr_count(\$matches[0], \"\n\")) .'"
                       . $this->_quote_replace($this->right_delimiter)
                       . "';")
                   , $source_content); 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?