<?php
//3語以上で分割する場合
function ex_explode($word_array, $str) {
$return = array();
//文字列を配列に入れる
$array = array($str);
//分割文字ごとにforeach
foreach ($word_array as $value1){
//文字列の配列を分割
foreach ($array as $key => $value2) {
$return = array_merge($return, explode($value1, $value2));
//配列の最後になったら初期化
if(count($array) - 1 === $key) {
$array = $return;
$return = array();
}
}
}
return $array;
}
//使う時
$word = 'タグ1,タグ2 タグ3 タグ4、タグ5';
ex_explode([' ',',','、',' ',],$word);
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme