分享好友 教程首页 教程搜索 频道列表

php中利用explode函数分割字符串到数组

2019-03-09 12:317020
+关注2
核心提示:分割字符串//利用 explode 函数分割字符串到数组?php $source = "hello1,hello2,he...
分割字符串 

//利用 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;

本文标签: #explode函数 #php #分割字符
整理员:网络转载
免责声明:凡注明来源本网的所有作品,均为本网合法拥有版权或有权使用的作品,欢迎转载,注明出处。非本网作品均来自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
生成海报
您可能在找更多
下一篇
我来说两句
抢沙发