protected function wordPos($haystack, $needle, $insensitive = true, $offset = 0, &$foundString = NULL)
    {
        if ($offset != 0) {
            $haystack = substr($haystack, $offset);
        }

        $parts = explode(' ', $needle);
        foreach ($parts as $i => $currPart) {
            $parts[$i] = preg_quote($currPart, '/');
        }

        $regex = '/(?<=\A|[\s\/\\.,;:_()-])' . implode('[\s\/\\.,;:_()-]', $parts) . '(?=[\s\/\\.,;:_()-]|$)/';
        if ($insensitive) {
             $regex .= 'i';
        }

        if (preg_match($regex, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
            $foundString = $matches[0][0];
            return (int)$matches[0][1];
        }

        return false;
    }
protected function wordPos($haystack, $needle, $insensitive = true, $offset = 0, &$foundString = NULL)
    {
        if ($offset != 0) {
            $haystack = substr($haystack, $offset);
        }

        $parts = explode(' ', $needle);
        foreach ($parts as $i => $currPart) {
            $parts[$i] = preg_quote($currPart, '/');
        }

        $regex = '/(?<=\A|[\s\/\\.,;:_()-])' . implode('[\s\/\\.,;:_()-]', $parts) . '(?=[\s\/\\.,;:_()-]|$)/';
        if ($insensitive) {
             $regex .= 'i';
        }

        if (preg_match($regex, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
            $foundString = $matches[0][0];
            return (int)$matches[0][1];
        }

        return false;
    }
protected function wordPos ( $ haystack , $ needle , $ insensitive = true , $ offset = 0 , & $ foundString = NULL ) { if ( $ offset != 0 ) { $ haystack = substr ( $ haystack , $ offset ) ; } $ parts = explode ( ' ' , $ needle ) ; foreach ( $ parts as $ i => $ currPart ) { $ parts [ $ i ] = preg_quote ( $ currPart , '/' ) ; } $ regex = '/(?<=\A|[\s\/\\.,;:_()-])' . implode ( '[\s\/\\.,;:_()-]' , $ parts ) . '(?=[\s\/\\.,;:_()-]|$)/' ; if ( $ insensitive ) { $ regex .= 'i' ; } if ( preg_match ( $ regex , $ haystack , $ matches , PREG_OFFSET_CAPTURE ) ) { $ foundString = $ matches [ 0 ] [ 0 ] ; return ( int ) $ matches [ 0 ] [ 1 ] ; } return false ; }
Find the position of the first occurrence of a word in a string.
@access protected
@param string $haystack The string to search in.
@param string $needle The string to search for.
@param boolean $insensitive (optional) Determines if we do a case-sensitive search (false) or a case-insensitive
one (true).
@param int $offset If specified, search will start this number of characters counted from the beginning of the
string. If the offset is negative, the search will start this number of characters counted from the end of the
string.
@param string $foundString String buffer that will contain the exact matching needle found. Set to NULL when
return value of the function is false.
@return mixed Returns the position of the needle (int) if found, false otherwise. Warning this function may
return Boolean false, but may also return a non-Boolean value which evaluates to false.
Find the position of the first occurrence of a word in a string .