str_replace 字符串匹配替换 explode 拆分数组
Posted 奔跑的葛根
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了str_replace 字符串匹配替换 explode 拆分数组相关的知识,希望对你有一定的参考价值。
str_replace 字符串匹配替换
$keyword="asp php,jsp"; $keyword=str_replace(" "," ",$keyword); echo $keyword; echo "<br>"; $keyword=str_replace(" ",",",$keyword); echo $keyword; echo "<br>"; $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 // 示例 1 $pizza = "piece1 piece2 piece3 piece4 piece5 piece6"; $pieces = explode(" ", $pizza); echo $pieces[0]; // piece1 echo $pieces[1]; // piece2 // 示例 2 $data = "foo:*:1023:1000::/home/foo:/bin/sh"; list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data); echo $user; // foo echo $pass; // * ?>
<?php $date = "04/30/1973"; list($month, $day, $year) = split (‘[/.-]‘, $date); echo "Month: $month; Day: $day; Year: $year<br />\n"; ?>
以上是关于str_replace 字符串匹配替换 explode 拆分数组的主要内容,如果未能解决你的问题,请参考以下文章