0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHPで連続して出現してくる文字列を成敗する方法

Last updated at Posted at 2022-04-06

正規表現??とか意味わからん

やりたいこととして、連続して出現してしまう文字列を一つに統一したかった。
↓みたいなやつを....

$fuck = 'test1,,,test2,,,,,test3,,test4,test5,,test6';

こうしたい

$fuck = 'test1,test2,test3,test4,test5,test6';

preg_replaceってやつを使ったらいけた。
preg_replace
読んでみたけどなんか難しいことばっかり書いてあるで
なんとか喰らいついて書いてみた

$fuck = preg_replace('|,+|', ',', 'test1,,,test2,,,,,test3,,test4,test5,,test6');

こんな感じでやればカンマ区切りで配列にできたのでうれしい。

$fuck = explode(',', preg_replace('|,+|', ',', 'test1,,,test2,,,,,test3,,test4,test5,,test6'));
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?