学习php中利用explode函数分割字符串到数组
16lz
2021-01-22
分割字符串
//利用 explode 函数分割字符串到数组
代码如下:
<?php $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串 $hello = explode(',',$source); for($index=0;$index<count($hello);$index++) { echo $hello[$index];echo "</br>"; } ?> //split函数进行字符分割 // 分隔符可以是斜线,点,或横线
代码如下:
<?php $date = "04/30/1973"; list($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year<br />\n"; ?>
通过数组实现多条件查询的代码
代码如下:
<?php$keyword="asp php,jsp";$keyword=str_replace(" "," ",$keyword);$keyword=str_replace(" ",",",$keyword);$keyarr=explode(',',$keyword); for($index=0;$index<count($keyarr);$index++) { $whereSql .= " And (arc.title like '%$keyarr[$index]%' Or arc.keywords like '%$keyarr[$index]%') ";} echo $whereSql;
相关学习推荐:PHP编程从入门到精通
更多相关文章
- PHP实现代码复用的traits新特性的方法
- 详解PHP论坛实现积分系统的思路代码
- 详解PHP网页缓存技术优点及代码实例
- php的字符串管理 zend_string
- php设计模式:桥接模式学习心得(附案例代码)
- PHP中运用jQuery的Ajax跨域调用代码详解
- 总结PHP字符串与数组处理函数用法
- 掌握php短信接口代码
- php如何安装bcmath扩展脚本?(附代码)