把字符串打散為數(shù)組:
<?php $str = "Hello world. I love Shanghai!"; print_r (explode(" ",$str)); ?>
explode() 函數(shù)把字符串打散為數(shù)組。
注釋:"separator" 參數(shù)不能是空字符串。
注釋:該函數(shù)是二進(jìn)制安全的。
explode(separator,string,limit)
參數(shù) | 描述 |
---|---|
separator | 必需。規(guī)定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit |
可選。規(guī)定所返回的數(shù)組元素的數(shù)目。 可能的值:
|
返回值: | 返回字符串的數(shù)組 |
PHP 版本: | 4+ |
更新日志: | 在 PHP 4.0.1 中,新增了 limit 參數(shù)。在 PHP 5.1.0 中,新增了對(duì)負(fù)數(shù) limit 的支持。 |
使用 limit 參數(shù)來返回一些數(shù)組元素:
<?php $str = 'one,two,three,four'; // 零 limit print_r(explode(',',$str,0)); // 正的 limit print_r(explode(',',$str,2)); // 負(fù)的 limit print_r(explode(',',$str,-1)); ?>
如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇
Powered by 365建站網(wǎng) RSS地圖 HTML地圖
copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號(hào)