没有单一的库函数可以为您提供相同的功能,但您可以获得一个单行:
原文链接:https://www.f2er.com/php/133178.html$str = "www.MysqL.com"; echo implode('.',array_slice(explode('.',$str),2)); // prints "www.MysqL" echo implode('.',-2)); // prints "MysqL.com"
轻松将其转换为功能:
function substring_index($subject,$delim,$count){ if($count < 0){ return implode($delim,array_slice(explode($delim,$subject),$count)); }else{ return implode($delim,$count)); } }