一个explode()函数会忽略引号内的字符? [英] An explode() function that ignores characters inside quotes?

查看:69
本文介绍了一个explode()函数会忽略引号内的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道快速,简单的explode()这样的函数可以忽略用一对任意字符(例如,引号)引起的分隔符吗?

Does somebody know a quick and easy explode() like function that can ignore splitter characters that are enclosed in a pair of arbitrary characters (e.g. quotes)?

示例:

my_explode(
  "/", 
  "This is/a string/that should be/exploded.//But 'not/here',/and 'not/here'"
);

应导致包含以下成员的数组:

should result in an array with the following members:

This is
a string 
that should be 
exploded.

But 'not/here', 
and 'not/here'

将字符用单引号引起来的事实将使它们免于分隔符的使用.

the fact that the characters are wrapped in single quotes would spare them from being splitters.

奖励积分可解决两个包装字符

Bonus points for a solution that can deal with two wrapper characters

(not/here)

首选本机PHP解决方案,但我认为不存在这种情况!

A native PHP solution would be preferred, but I don't think such a thing exists!

推荐答案

($str, '/')

在链接的页面上有一个< 5.3的配方.

There's a recipe for <5.3 on the linked page.

这篇关于一个explode()函数会忽略引号内的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆