LoginSignup
28

More than 5 years have passed since last update.

改行タブをスペースへ、複数スペースを1つへ変換

Last updated at Posted at 2014-10-28
    private function __trim($str)
    {
        // 両サイドのスペースを消す
        $str = trim($str);
        // 改行、タブをスペースへ
        $str = preg_replace('/[\n\r\t]/', '', $str);
        // 複数スペースを一つへ
        $str = preg_replace('/\s(?=\s)/', '', $str);

        return $str;
    }

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
28