2
首先一個字符串,我已經看到了下面的問題已:爆炸有兩個分隔符
- Php - explode a string with two delimiters
- explode an array of delimited strings into two arrays
- PHP explode/split with 2 different delimiters
多。如果我有一個這樣的輸入:
[email protected]#C
[email protected]#c
對於每個線路,我有兩個分隔符@
和#
,我想有他們分離成陣列是這樣的:
Array
(
[0] => A
[1] => B
[2] => C
)
Array
(
[0] => a
[1] => b
[2] => c
)
我有這樣的循環代碼:
foreach (explode(PHP_EOL, $input) as $line) {
$line = explode("@", $line);
$line[1] = explode("#", $line[1]);
}
我知道我在做什麼是錯誤的。我得到的輸出是:
Array
(
[0] => A
[1] => Array
(
[0] => B
[1] => C
)
)
Array
(
[0] => a
[1] => Array
(
[0] => b
[1] => c
)
)
我出出主意想別的,所以,有人可以請指導我如何將字符串分割在同一陣列內? ps:我不想用regex!
是輸入1字符串還是2? – Rizier123 2014-11-04 23:52:32
@ Rizier123我不明白。 1或2是什麼意思? – 2014-11-04 23:53:39
是這樣的:'$ input1 =「A @ B#C」; $ input2 =「a @ b#c」;'或者是這樣的:'$ input =「A @ B#C a @ b#c」;' – Rizier123 2014-11-04 23:54:45