如果爆炸字符串并且所说的字符串不包含定界符,爆炸是否会引发错误? [英] If you explode a string and said string does not contain the delimiter, does explode kick an error?

查看:72
本文介绍了如果爆炸字符串并且所说的字符串不包含定界符,爆炸是否会引发错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用php获取了一部分网址。此部分可能带有尾随的?值。因此,例如:我爆炸了URL:stackoverflow.com/questions,我想询问问题,所以我做了 explode(’/’,$ url)之类的事情。在此示例中,URL可能如下所示:stackoverflow.com/questions?query。我不希望该结尾为 query,所以我会进行爆炸('?',$ questionurl [no。])。但是,当字符串不包含定界符时,爆炸如何处理?它只是按原样返回字符串还是返回false?

So I'm getting a section of the url with php. This section may or may not have trailing '?' values. So for example : I'm exploding the url : stackoverflow.com/questions and I want to get questions so i do something like explode ('/',$url). Pretend in this example the url might be as follows : stackoverflow.com/questions?query. I don't want that ending 'query' so I do explode ('?',$questionurl[no.]). However how does explode handle when the string doesn't contain the delimiter? Does it just return the string as it was or does it return false?

我已经阅读了php文档并查看了堆栈中的问题,但似乎不太清楚找到确切的方案。

I've read through the php document and looked though questions in stack but can't quite seem to find this exact scenario.

我可以自己进行测试,但是我正在使用的环境已设置为可与drupal一起使用。因此,要想测试一个简单的查询,将需要进行大量的混乱工作,我认为这对所有参与者和将来的聚会都将更加有用。

I would be able to test this myself however the environment I'm working in is set up to work with drupal. As such it would require quite alot of messing around to be able to test one simple query, I figured it would more useful for all and future parties, here.

推荐答案

请阅读php文档。它存在是有原因的。

Please read the php docs. It exists for a reason.

http://be2.php.net/explode


返回通过在分隔符形成的边界上分割字符串参数
而创建的字符串数组。

Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter.

如果定界符为空字符串(),则explode()将返回FALSE。如果
分隔符包含的值不包含在字符串中,并且使用了
负数限制,则将返回一个空数组,否则将返回
,否则将返回一个包含字符串的数组。

If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.

这篇关于如果爆炸字符串并且所说的字符串不包含定界符,爆炸是否会引发错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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