LoginSignup
0
1

More than 3 years have passed since last update.

PHPで複数の文字で文字列を分割する

Last updated at Posted at 2020-12-23

たとえば「#」「/」で分割するとき

code

$result = preg_split('/(#|\/)/', $str);

sample

$str = 'タグ1#タグ2/タグ3/タグ4#タグ5';
var_dump(preg_split('/(#|\/)/', $str));

// result
array(5) {
  [0]=>
  string(7) "タグ1"
  [1]=>
  string(7) "タグ2"
  [2]=>
  string(7) "タグ3"
  [3]=>
  string(7) "タグ4"
  [4]=>
  string(7) "タグ5"
}
0
1
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
1