9
7

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.

preg_replaceでnullが返却される際の対処

Posted at

概要

preg_replaceで一部(sとか)のパターン修飾子を使用しており、かつ処理する文字列の容量が大きいと
正規表現に間違いがないにも関わらずnullが返却されることがある

パターン修飾子参考:
http://php.net/manual/ja/reference.pcre.pattern.modifiers.php

対策

pcre.backtrack_limitの値を増やすと問題が解決できる。

// デフォルト値は1000000
ini_set('pcre.backtrack_limit', 100000000);

疑問

  • 値を増やすことに対するデメリットが無ければもっと大きな値にしてもいいが、怖い
  • 一部のパターン修飾子しかこのパラメータは反応しないらしい…
    • 今回sしか確認できてない
9
7
2

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
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?