Skip to content

Instantly share code, notes, and snippets.

@suin
Last active February 19, 2016 11:07
Show Gist options
  • Save suin/1500355 to your computer and use it in GitHub Desktop.
Save suin/1500355 to your computer and use it in GitHub Desktop.
改行テキストを配列に変換する ref: http://qiita.com/suin/items/835ac0f58e6d3bbb6280
$text = 'a
b
c
d
f
';
$array = explode("\n", $text); // とりあえず行に分割
$array = array_map('trim', $array); // 各行にtrim()をかける
$array = array_filter($array, 'strlen'); // 文字数が0の行を取り除く
$array = array_values($array); // これはキーを連番に振りなおしてるだけ
array(5) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
[3]=>
string(1) "d"
[4]=>
string(1) "f"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment