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入门教程之表单与验证实例详解

本文实例讲述了PHP表单与验证。分享给大家供大家参考,具体如下: Demo1.php <?php ob_start(); //重新导向一个 URL //he...

php错误、异常处理机制(补充)

一、错误处理 异常处理: 意外,是在程序运行过程中发生的意料这外的事,使用异常改变脚本正常流程 PHP5中的一个新的重要特性 复制代码 代码如下: if(){ }else{ } try...

Snoopy类使用小例子

    snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。 下面是它的一些特征: 1、方便抓取网页的内容 2、方便抓取网页的文...

PHP创建对象的六种方式实例总结

PHP创建对象的六种方式实例总结

本文实例讲述了PHP创建对象的六种方式。分享给大家供大家参考,具体如下: <?php /** * PHP创建对象的六种方式 */ class Person{ p...

用php来改写404错误页让你的页面更友好

404错误,很多人都知道,如果要访问的url不存在的时候就读取显示这个页面.以往在处理404方面我们通常的做法是要麽简单写几行字,而有心人士或许还会对其稍加美化,另外一少部份想投机取巧的...