PHP:分割字串 [英] PHP: Split string
本文介绍了PHP:分割字串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在PHP中用.
分隔符分割字符串?例如,如果我有字符串"a.b"
,该如何获取"a"
?
How do I split a string by .
delimiter in PHP? For example, if I have the string "a.b"
, how do I get "a"
?
推荐答案
explode
: /p>
explode
does the job:
$parts = explode('.', $string);
您还可以直接将部分结果提取到变量中:
You can also directly fetch parts of the result into variables:
list($part1, $part2) = explode('.', $string);
这篇关于PHP:分割字串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文