我正在为 SlashCategory ,它要求我根据 并创建一个数组: p>
但是,我遇到了问题。 如果正斜杠前面有反斜杠,我不希望 我想要 有一个数组包含: p>
不: p>
我该怎么做? p>
div> / code>字符拆分(或标记化)每个字符串。 我使用PHP的
explode() code>函数,效果很好。 例如,它需要以下内容: p>
书籍/标题/苍蝇之王/作者/ William Golding code> p>
[0] Book
[1] Title
[2] Lord of The Flies
[3]作者
[4] William Golding
code> pre>
explode() code>分解字符串。 例如: p>
Url / Google / http:\ / \ / www.google.com code> p>
[0] Url
[1] Google
[2] http://www.google.com
code> < / pre>
[0] Url
[1] Google
[2] http:
[3]
[4] www.google.com
code> pre>
I am making a parser for my SlashCategory, which requires me to split (or tokenize) each string based on the /
character. I am using PHP's explode()
function, which works well. For example, it takes the following:
Book/Title/Lord Of The Flies/Author/William Golding
And creates an array with:
[0] Book
[1] Title
[2] Lord Of The Flies
[3] Author
[4] William Golding
However, I have a problem. I do not want explode()
to break up the string if the forward slash is preceded by a backslash. For example:
Url/Google/http:\/\/www.google.com
I want to have an array containing:
[0] Url
[1] Google
[2] http://www.google.com
Not:
[0] Url
[1] Google
[2] http:
[3]
[4] www.google.com
How can I do this?