1

こんにちは、Preg_match_all 関数を使用して文字列を調べ、その値の配列を返します。

$str = 'field1,field2,field3,field4,,,,,,,"some text, some other text",field6';

preg_match_all("~\"[^\"]++\"|[^,]++~", $str,$match);

echo "<pre>";
print_r($match[0]);
echo "<pre>";

これを返します。

Array
(
[0] => field1
[1] => field2
[2] => field3
[3] => field4
[4] => "some text, some other text"
[5] => field6
)

しかし、私はまた、空白のものを返して助けてほしい.

4

3 に答える 3

-2

爆発も使えると思います。

my_array = explode (',', $str);

注意: 「テキスト、その他のテキスト」は、配列の 2 つのセルで分離されます。

于 2013-06-13T19:32:22.190 に答える