Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

概要

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

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

対策

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

http://php.net/manual/ja/pcre.configuration.php

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

疑問

  • 値を増やすことに対するデメリットが無ければもっと大きな値にしてもいいが、怖い
  • 一部のパターン修飾子しかこのパラメータは反応しないらしい…
    • 今回sしか確認できてない
HikaruYokogoshi
渋谷ではたらくエンジニアです。ずっとプログラマで食っていきたい
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした