public function substring($text, $searchword, $length = 200)
    {
        $textlen = AnHelperString::strlen($text);
        $lsearchword = AnHelperString::strtolower($searchword);
        $wordfound = false;
        $pos = 0;

        while ($wordfound === false && $pos < $textlen) {
            if (($wordpos = @AnHelperString::strpos($text, ' ', $pos + $length)) !== false) {
                $chunk_size = $wordpos - $pos;
            } else {
                $chunk_size = $length;
            }

            $chunk = AnHelperString::substr($text, $pos, $chunk_size);
            $wordfound = AnHelperString::strpos(AnHelperString::strtolower($chunk), $lsearchword);

            if ($wordfound === false) {
                $pos += $chunk_size + 1;
            }
        }//while

        if ($wordfound !== false) {
            return (($pos > 0) ? '...&nbsp;' : '').$chunk.'&nbsp;...';
        } else {
            if (($wordpos = @AnHelperString::strpos($text, ' ', $length)) !== false) {
                return AnHelperString::substr($text, 0, $wordpos).'&nbsp;...';
            } else {
                return AnHelperString::substr($text, 0, $length);
            }
        }
    }
public function substring($text, $searchword, $length = 200)
    {
        $textlen = AnHelperString::strlen($text);
        $lsearchword = AnHelperString::strtolower($searchword);
        $wordfound = false;
        $pos = 0;

        while ($wordfound === false && $pos < $textlen) {
            if (($wordpos = @AnHelperString::strpos($text, ' ', $pos + $length)) !== false) {
                $chunk_size = $wordpos - $pos;
            } else {
                $chunk_size = $length;
            }

            $chunk = AnHelperString::substr($text, $pos, $chunk_size);
            $wordfound = AnHelperString::strpos(AnHelperString::strtolower($chunk), $lsearchword);

            if ($wordfound === false) {
                $pos += $chunk_size + 1;
            }
        }//while

        if ($wordfound !== false) {
            return (($pos > 0) ? '...&nbsp;' : '').$chunk.'&nbsp;...';
        } else {
            if (($wordpos = @AnHelperString::strpos($text, ' ', $length)) !== false) {
                return AnHelperString::substr($text, 0, $wordpos).'&nbsp;...';
            } else {
                return AnHelperString::substr($text, 0, $length);
            }
        }
    }
public function substring ( $ text , $ searchword , $ length = 200 ) { $ textlen = AnHelperString :: strlen ( $ text ) ; $ lsearchword = AnHelperString :: strtolower ( $ searchword ) ; $ wordfound = false ; $ pos = 0 ; while ( $ wordfound === false && $ pos < $ textlen ) { if ( ( $ wordpos = @ AnHelperString :: strpos ( $ text , ' ' , $ pos + $ length ) ) !== false ) { $ chunk_size = $ wordpos - $ pos ; } else { $ chunk_size = $ length ; } $ chunk = AnHelperString :: substr ( $ text , $ pos , $ chunk_size ) ; $ wordfound = AnHelperString :: strpos ( AnHelperString :: strtolower ( $ chunk ) , $ lsearchword ) ; if ( $ wordfound === false ) { $ pos += $ chunk_size + 1 ; } } //while if ( $ wordfound !== false ) { return ( ( $ pos > 0 ) ? '...&nbsp;' : '' ) . $ chunk . '&nbsp;...' ; } else { if ( ( $ wordpos = @ AnHelperString :: strpos ( $ text , ' ' , $ length ) ) !== false ) { return AnHelperString :: substr ( $ text , 0 , $ wordpos ) . '&nbsp;...' ; } else { return AnHelperString :: substr ( $ text , 0 , $ length ) ; } } }
returns substring of characters around a searchword.

@param string The source string
@param int Number of chars to return
@param string The searchword to select around

@return string
returns substring of characters around a searchword .