$arrWord = array('Key', 'w ord', '12345678');
$resTrie = trie_filter_new();
echo "\nsave key\n";
foreach ($arrWord as $k => $v) {
    echo "id:", $k, ' -> ', $v, "\n";
    trie_filter_store($resTrie, $k, $v, TRIE_FILTER_UP | TRIE_FILTER_SP | TRIE_FILTER_NUM);
}
//去掉关键字中的空格 小写转为大写 数字转为0
//实际相当于 array('WORD', 'KEY', '00000000');
trie_filter_save($resTrie, __DIR__ . '/blackword.tree');
$resTrie = trie_filter_load(__DIR__ . '/blackword.tree');
$strContent = 'hello wo rd WORD kEy 0123456789';
$arrRet = trie_filter_search_all($resTrie, $strContent, TRIE_FILTER_UP | TRIE_FILTER_SP | TRIE_FILTER_NUM);
//小写转为大写 数字转为0 忽略文本中的空格
//实际相当于 'HELLOWORDWORDKEY0000000000'
print_all($strContent, $arrRet);
function print_all($str, $res)
{
    echo "\ntext:{$str}\n", "\nmatch ", count($res) / 3, "\n";
    for ($i = 0, $c = count($res); $i < $c; $i += 3) {
        echo 'id:', $res[$i + 2], ' -> ', substr($str, $res[$i], $res[$i + 1]), "\n";
    }
}
trie_filter_free($resTrie);
/*输出为

save key
id:0 -> Key
id:1 -> w ord
id:2 -> 12345678
$resTrie = trie_filter_load(__DIR__ . '/blackword.tree');
$str = 'hello word2 haha word1 word4 word2';
$arrRet = trie_filter_search($resTrie, $str);
print_all($str, array($arrRet));
//Array(0 => 6, 1 => 5)
echo "\ntest1///////////////////\n";
$str = 'hello word2 haha word1 word4 word2';
$arrRet = trie_filter_search_all($resTrie, $str);
print_all($str, $arrRet);
echo "\ntest2///////////////////\n";
$str = 'hello word';
$arrRet = trie_filter_search($resTrie, $str);
print_all($str, array($arrRet));
//Array()
$arrRet = trie_filter_search_all($resTrie, 'hello word');
print_all($str, $arrRet);
echo "\ntest3///////////////////\n";
echo "start memory=" . memory_get_usage(true) . "\n";
date_default_timezone_set('Asia/Chongqing');
$test = array('a', 'abd', 'dad', 'pab', 'dda', 'word1f', 'cword1', 'cword1t');
foreach ($test as $v) {
    //    echo "per start memory=".memory_get_usage(true)."\n";
    $arrRet = trie_filter_search_all($resTrie, $v);
    //  echo "per end memory=".memory_get_usage(true)."\n";
    //print_all($v, $arrRet);
}
echo "end memory=" . memory_get_usage(true) . "\n";
echo date('Y-m-d H:i:s');
trie_filter_free($resTrie);
function print_all($str, $res)
{
Exemplo n.º 3
0
        }
        if (ereg("Emergency stop", $msg) or ereg("No pages of output", $msg)) {
            $msg = ereg_replace("^.*aux))", "ERREUR : ", $msg);
            $msg = ereg_replace("No pages of output.*\$", "No pages of ouput", $msg);
            print "<BR> <BOLD> <br> <B> ERREUR D'INTERPRETATION dans {$filename} !!!! </B> <BR> {$msg} <BR>";
        } else {
            print_all("portrait");
            print "<BR> <BOLD> <br> <B> semble ok dans {$filename} !!!! </B> <BR> {$msg} <BR>";
        }
    }
    if ($nb_pages_landscape) {
        fwrite($file_landscape_out, $conclusion);
        fclose($file_landscape_out);
        system("compile_landscape.bat > out");
        //print "res=$status";
        print_all("landscape");
    }
    print "<BR> " . ($nb_pages_portrait + $nb_pages_landscape) . " crées<BR> ";
} else {
    print "pas de imprime en attente <BR>";
}
print "<BR> <a href='../admin/index.php'>  Retour Administration </a>\n";
function print_all($orientation)
{
    global $printer;
    @mkdir("c:/Oyak/ToPrint", 0755);
    if ($printer == "default") {
        copy("all_{$orientation}.ps", "c:/Oyak/ToPrint/imprime_{$orientation}.ps");
        copy("all_{$orientation}.ps", "c:/Oyak/imprime_{$orientation}.ps");
    } else {
        @mkdir("c:/Oyak/ToPrint/{$printer}", 0755);
Exemplo n.º 4
0
echo "<br/>{$a}";
doubler($a);
echo "<br/>{$a}";
doubler($a);
echo "<br/>{$a}";
doubler($a);
echo "<br/>{$a}";
// variable parameters
function print_all()
{
    $params = func_get_args();
    foreach ($params as $param) {
        echo "<br/>{$param}";
    }
}
print_all('a', 'e', 'i', 'o', 'u');
// return by reference
$names = array('a man', 'b man', 'c man');
function &getNames()
{
    global $names;
    return $names;
}
$names_ref =& getNames();
$names_ref[0] = 'p-man';
echo "<br/>{$names['0']}";
// variable function
$func = 'print_all';
$func('yo', 'momma', 'so', 'fat');
//  anonymous function
$array = array("really long string here, boy", "this", "middling length", "larger");