def php_substr_count(_haystack, _needle, _offset=0, _length=None):
    """
    >>> text = 'This is a test'
    >>> php_strlen(text)
    14
    >>> php_substr_count(text, 'is')
    2
    >>> php_substr_count(text, 'is', 3)
    1
    >>> php_substr_count(text, 'is', 3, 3)
    0
    >>> php_substr_count(text, 'is', 5, 10)
    1
    >>> php_substr_count('gcdgcdgcd', 'gcdgcd')
    1
    """
    if _length is None:
        _length = len(_haystack)
    return _haystack.count(_needle, _offset, _offset + _length)