<?php
/*

    This script verify if some term is like, or is content, in some text block
    Este script verifica se um termo se parece, ou esta incluindo e algum bloco de texto
    
    Developed by Andreas Diegues
    andreas@aboutdesign.com.br
    V1.0

    Example:
    echo isLike("this is a test", "i love a simple nice test!");
    returns 2/4
    it means, 2 words match in a block of four words
    
    Exemplo:
    echo isLike("this is a test", "i love a simple nice test!");
    retorna 2/4
    isso significa, 2 palavras combinam em um bloco de quatro palavras

*/

function isLike($term, $block) {

    $like = 0;

    $term = ereg_replace(" ", "{[s.e.p]}", $term);
    $term = ereg_replace("-", "{[s.e.p]}", $term);
    $term = ereg_replace("/", "{[s.e.p]}", $term);
    $term = ereg_replace("&", "{[s.e.p]}", $term);
    $term = ereg_replace("@", "{[s.e.p]}", $term);
    $term = ereg_replace("\+", "{[s.e.p]}", $term);
    
    $word = explode("{[s.e.p]}", $term);
    $totalWords = count($word);
    
    for($i = 0; $i < $totalWords; $i++) {
        if(eregi($word[$i], $block)) {
            $like++;
        }
    }
    
    return $like."/".$totalWords;
}
?>