fir*_*ire 0 php string explode
我正在寻找一个explode类型函数,它将按字符分解字符串,但如果字符在其中,则还要取一个字符列表来忽略.
例如:
$str = "hello, this is, a test 'some, string' thanks";
explode_func($str, ",", "'");
Run Code Online (Sandbox Code Playgroud)
这会爆炸$str,,但忽略任何,内部'
预期产量:
Array
(
[0] => hello
[1] => this is
[2] => a test
[3] => thanks
)
Run Code Online (Sandbox Code Playgroud)
另一个例子是:
$str = "hello, this is, a test (some, string) thanks";
explode_func($str, ",", "()");
Run Code Online (Sandbox Code Playgroud)
这会爆炸$str的,,但忽略任何,之间(,并)得到相同的输出.
有任何想法吗?
$str = "hello, this is, a test 'some, string' thanks";
$array = str_getcsv($str, ",", "'");
Run Code Online (Sandbox Code Playgroud)
哪个应该给:
Array
(
[0] => hello
[1] => this is
[2] => a test 'some, string' thanks
)
Run Code Online (Sandbox Code Playgroud)