コード例 #1
0
ファイル: buoy.php プロジェクト: Thomas-C-Garrett/Sound
/**
 * Find the position of the Xth occurrence of a substring in a string
 * @param $haystack
 * @param $needle
 * @param $number integer > 0
 * @return int
 */
function strposX($haystack, $needle, $number)
{
    if ($number == 1) {
        return strpos($haystack, $needle);
    }
    return strpos($haystack, $needle, strposX($haystack, $needle, $number - 1) + strlen($needle));
}
コード例 #2
0
function strposX($haystack, $needle, $number)
{
    if ($number == '1') {
        return strpos($haystack, $needle);
    } elseif ($number > '1') {
        return strpos($haystack, $needle, strposX($haystack, $needle, $number - 1) + strlen($needle));
    } else {
        return false;
    }
}