php 函数 js

strpos($batch_id,'|')>0     //返回竖线所在下标  不存在返回 空
$idsArray = explode(",",$userIds);   //将字符串拆分成数组

$text = implode("|", $vegetables);  //将数组转换成字符串
elseif (strpos($pid, '15_') === 0 && $pid != '15_0') {
 $pid = str_replace('15_', '', $pid);      //$pid = 15_5   5   将$pid中的'15_'用空格替换

echo str_replace("world","John","Hello world!"); //Hello John!
echo strpos("Hello world!","wo"); //6 从前到后查
echo strrpos("Hello world!","wo"); //6 查找字符串在另一个字符串中最后一次出现的位置。
cid = cid.toString().indexOf("_0") != -1? 0 : cid;

js

strs=str.split(","); //字符分割 

      数组里面查找元素(返回元素的下标,不存在返回-1)

搜索字符串

var
array = [2, 5, 9]; var index = array.indexOf(2); // index is 0 index = array.indexOf(7); // index is -1
lastIndexOf   //返回元素在数组中最后出现的下标,没有返回-1
截取字符串  

var str = "abcdefghij"; alert(str.substring(0,3));//输出:abc   alert(str.substr(0,3));//输出:abc   alert(str.substring(2,6));//输出:cdef   alert(str.substr(2,6));//输出:cdefgh   alert(str.substring(3));//输出:defghij   alert(str.substr(3));//输出:defghij

实例:

js  $pid.split("_");
js $pid.toString().indexOf("_")>0
php  strpos($pid,"_")>0
php  $ssd = explode('_',$pid);
php  intval($user->id)  //转整形
php $name = mb_strcut($value['name'], 0, 10,'utf-8') . '...'; //截取字符串乱码问题
php $suffix= substr($name, strrpos($name, '.') + 1);  //获取文件后缀名
原文地址:https://www.cnblogs.com/suxiaolong/p/5527915.html