LoginSignup
0
0

More than 5 years have passed since last update.

PHPの正規表現の書き方

Last updated at Posted at 2018-05-14

記述方法

正規表現のパターンをデリミタ(区切り文字)で囲う
通常はスラッシュだが、英数字とバックスラッシュ以外であれば何でも良い

/[0-9]/

エスケープ

正規表現では特殊文字を通常の文字として認識させる時はバックスラッシュを使い
エスケープを行う
スラッシュを文字として認識させる場合

/\//

正規表現の種類

[?]直前の表現を0回または1回繰り返す 例ab?→a,abとマッチ

URIの前後の スラッシュ / を取り除く方法

test.php
  $patterns = array(
    '/\/?$/',
    '/^\/*/',
  );

  //URIの取得
  $param = preg_replace($patterns,'',$_SERVER['REQUEST_URI']);
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