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

yipeiwu_com6年前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;

相关文章

PHP实现的AES 128位加密算法示例

本文实例讲述了PHP实现的AES 128位加密算法。分享给大家供大家参考,具体如下: /* 加密算法一般分为两种:对称加密算法和非对称加密算法。 对称加密 对称加密算法是消息发送者和...

php数组函数序列之in_array() 查找数组值是否存在

in_array() 定义和用法 in_array() 函数在数组中搜索给定的值。 语法 in_array(value,array,type) 参数 描述 value 必需。规定要在数组...

Discuz板块横排显示图片的实现方法

到你目前在使用的模板中寻找 discuz.htm 找到这一段代码: 复制代码 代码如下:<td width="$cat[forumcolwidth]" ...

PHP请求远程地址设置超时时间的解决方法

php请求远程地址设置超时时间,主要讲解file_get_contents、fopen、curl这三个简单常用函数设置超时时间的方法,一般情况下建议使用curl,性能最好,效率也最高。...

解决Laravel blade模板转义html标签的问题

解决Laravel blade模板转义html标签的问题

解决Laravel blade模板转义html标签的问题: 后台textarea提交到表里面的数据展现到前端页面时(在后台已使用nl2br()函数进行转换),直接显示如下: 很尴尬!!...