Welcome Guest, Not a member yet? Register   Sign In
Extract text from MEDIUM TEXT
#4

[eluser]abmcr[/eluser]
Code:
function becca($stringa_ricercata,$text,$parole=25,$end_char="...")
    {
        $CI =& get_instance();
        $CI->load->helper("text");
        $init=strripos(($text),($stringa_ricercata)); //posizione parola
        if ($init==0) return highlight_phrase(word_limiter($text,$parole), $stringa_ricercata, '<span style="color:#990000">', '</span>');//esce se รจ il primo in realta' word_limiter
        $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", strtolower($text))));
        $parola=array_keys($words, strtolower($stringa_ricercata));
        $posto_parola=$parola[0]; //numero parola
        $ini=(($posto_parola-$parole)<0?0:($posto_parola-$parole));
        $end=(($posto_parola+$parole)>count($words)?count($words):($posto_parola+$parole));
        if (count($words) <= $parole)
        {
            return highlight_phrase(trim($text), $stringa_ricercata, '<span style="color:#990000">', '</span>');
        }

        $str = '';
        for ($i = $ini; $i < $end; $i++)
        {
            $str .= $words[$i].' ';
        }
        if ($ini>0) $str=$end_char.$str;
        return highlight_phrase(trim($str).$end_char, $stringa_ricercata, '<span style="color:#990000">', '</span>');
    }

i have made a function in a librarie... that's because i use $CI->

Thank you


Messages In This Thread
Extract text from MEDIUM TEXT - by El Forum - 08-08-2008, 05:16 AM
Extract text from MEDIUM TEXT - by El Forum - 08-08-2008, 07:05 AM
Extract text from MEDIUM TEXT - by El Forum - 08-08-2008, 07:13 AM
Extract text from MEDIUM TEXT - by El Forum - 08-08-2008, 07:35 AM
Extract text from MEDIUM TEXT - by El Forum - 08-08-2008, 08:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB