Php 用于多字符的自定义分解函数
我用PHP编写自定义分解函数。它适用于一个字符,但如何对多个字符进行修改? 如果更改此代码,请仅使用strlen()函数Php 用于多字符的自定义分解函数,php,Php,我用PHP编写自定义分解函数。它适用于一个字符,但如何对多个字符进行修改? 如果更改此代码,请仅使用strlen()函数 function myExplode($delimiter,$str){ $arr=[]; $s=""; $count=0; for ($i=0; $i < strlen($str); $i++) { if ($str[$i]!=$delimiter) { $s=$s.$str[$i]; if (!isset($str[$
function myExplode($delimiter,$str){
$arr=[];
$s="";
$count=0;
for ($i=0; $i < strlen($str); $i++) {
if ($str[$i]!=$delimiter) {
$s=$s.$str[$i];
if (!isset($str[$i+1])) {
$arr[$count]=$s;
$count++;
$s="";
}
}
else{
$arr[$count]=$s;
$count++;
$s="";
}
}
return $arr;
}
$hello="Hello World,this is me";
$explodedArr=myExplode("is",$hello);
print_r($explodedArr);
函数myExplode($delimiter,$str){
$arr=[];
$s=“”;
$count=0;
对于($i=0;$i
为什么不简单地使用正则表达式呢?为什么在正则表达式已经存在时编写它呢?