爆炸功能不在爆炸字符中
我正在寻找一个 explode
类型的函数,该函数将按字符分解字符串,但也会获取一个字符列表以忽略该字符是否在其中。
例如:
$str = "hello, this is, a test 'some, string' thanks";
explode_func($str, ",", "'");
这会将 $str
分解为 ,
,但忽略 '
中的任何 ,
预期输出:
Array
(
[0] => hello
[1] => this is
[2] => a test
[3] => thanks
)
另一个示例是be:
$str = "hello, this is, a test (some, string) thanks";
explode_func($str, ",", "()");
这会将 $str
分解为 ,
,但忽略 (
和 ),
code> 获得相同的输出。
有什么想法吗?
I am looking for an explode
type function that will explode a string by characters but also take a list of characters to ignore if the character is within them.
For example:
$str = "hello, this is, a test 'some, string' thanks";
explode_func($str, ",", "'");
This would explode $str
by ,
but ignore any ,
within '
Expected output:
Array
(
[0] => hello
[1] => this is
[2] => a test
[3] => thanks
)
Another example would be:
$str = "hello, this is, a test (some, string) thanks";
explode_func($str, ",", "()");
This would explode $str
by ,
but ignore any ,
between (
and )
to get the same output.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
str_getcsv()
应该给出:
str_getcsv()
which should give:
最好的选择是首先删除您想要忽略的区域。
用法:
未经测试,但理论可靠
Your best bet would be to remove the areas you want to ignore first.
usage:
Not tested but the theory is solid