1
是否有準備好的函數來獲取位置數組,其中某個子字符串開始?如何獲取PHP中所有子字符串出現的起始位置?
例如,
$needle = "apple";
$haystack = "one apple two apples three apples";
$r = f($haystack , $needle);
// should give:
$r = array(4 , 13 , 24);
// i.e. the positions of "a" letters
我知道substr_count給人子的數目,但我怎麼能得到的起始位置?
感謝您的幫助!