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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-19 我要评论
想了解php中利用explode函数分割字符串到数组的相关内容吗,在本文为您仔细讲解php分割字符串的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,分割字符串,下面大家一起来学习吧。
分割字符串

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们