当前位置: 首页>>代码示例>>PHP>>正文


PHP readInt函数代码示例

本文整理汇总了PHP中readInt函数的典型用法代码示例。如果您正苦于以下问题:PHP readInt函数的具体用法?PHP readInt怎么用?PHP readInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了readInt函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: search

function search($file, $word, &$statsList)
{
    $index = computeIndex($word);
    if ($index != -1) {
        fseek($file, $index * 4 + 4);
        // 4 bytes per entry, skip header
        $index = readInt($file);
        if ($index) {
            $start = sizeof($statsList);
            $count = $start;
            fseek($file, $index);
            $w = readString($file);
            while ($w) {
                $statIdx = readInt($file);
                if ($word == substr($w, 0, strlen($word))) {
                    // found word that matches (as substring)
                    $statsList[$count++] = array("word" => $word, "match" => $w, "index" => $statIdx, "full" => strlen($w) == strlen($word), "docs" => array());
                }
                $w = readString($file);
            }
            $totalHi = 0;
            $totalFreqHi = 0;
            $totalFreqLo = 0;
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                $multiplier = 1;
                // whole word matches have a double weight
                if ($statInfo["full"]) {
                    $multiplier = 2;
                }
                fseek($file, $statInfo["index"]);
                $numDocs = readInt($file);
                $docInfo = array();
                // read docs info + occurrence frequency of the word
                for ($i = 0; $i < $numDocs; $i++) {
                    $idx = readInt($file);
                    $freq = readInt($file);
                    $docInfo[$i] = array("idx" => $idx, "freq" => $freq >> 1, "rank" => 0.0, "hi" => $freq & 1);
                    if ($freq & 1) {
                        $totalHi++;
                        $totalFreqHi += $freq * $multiplier;
                    } else {
                        $totalFreqLo += $freq * $multiplier;
                    }
                }
                // read name and url info for the doc
                for ($i = 0; $i < $numDocs; $i++) {
                    fseek($file, $docInfo[$i]["idx"]);
                    $docInfo[$i]["name"] = readString($file);
                    $docInfo[$i]["url"] = readString($file);
                }
                $statInfo["docs"] = $docInfo;
            }
            $totalFreq = ($totalHi + 1) * $totalFreqLo + $totalFreqHi;
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                $multiplier = 1;
                // whole word matches have a double weight
                if ($statInfo["full"]) {
                    $multiplier = 2;
                }
                for ($i = 0; $i < sizeof($statInfo["docs"]); $i++) {
                    $docInfo =& $statInfo["docs"];
                    // compute frequency rank of the word in each doc
                    $freq = $docInfo[$i]["freq"];
                    if ($docInfo[$i]["hi"]) {
                        $statInfo["docs"][$i]["rank"] = (double) ($freq * $multiplier + $totalFreqLo) / $totalFreq;
                    } else {
                        $statInfo["docs"][$i]["rank"] = (double) ($freq * $multiplier) / $totalFreq;
                    }
                }
            }
        }
    }
    return $statsList;
}
开发者ID:ninghang,项目名称:bayesianPlay,代码行数:76,代码来源:search.php

示例2: readEPG

function readEPG($epgdatabase)
{
    $fd = fopen($epgdatabase, "r");
    while (!feof($fd)) {
        $length = readInt($fd, 4);
        if ($length < 0) {
            break;
        }
        //echo "$length\n";
        $json = array();
        decodeLength($fd, $length, $json);
        if (isset($json["__section__"])) {
            $section = $json["__section__"];
            echo json_encdat($json) . "\n";
            continue;
        }
        if ($section != "broadcasts") {
            continue;
        }
        $channel = $json["channel"];
        $channel = $GLOBALS["channels"][$channel];
        $service = $channel["services"];
        $service = $GLOBALS["services"][$service[0]];
        if (isset($service["svcname"])) {
            $json["channel"] = $service["svcname"];
        }
        if (isset($service["provider"])) {
            $json["provider"] = $service["provider"];
        }
        if (isset($service["networkname"])) {
            $json["network"] = $service["networkname"];
        }
        $json["tags"] = array();
        $tags = $channel["tags"];
        for ($inx = 0; $inx < count($tags); $inx++) {
            $json["tags"][] = $GLOBALS["tags"][$tags[$inx]]["name"];
        }
        unset($json["grabber"]);
        unset($json["episode"]);
        echo json_encdat($json) . "\n";
    }
}
开发者ID:patrickz98,项目名称:xavaro,代码行数:42,代码来源:EPGDatabaseDump.php

示例3: search

function search($file, $word, &$statsList)
{
    $index = computeIndex($word);
    if ($index != -1) {
        fseek($file, $index * 4 + 4);
        // 4 bytes per entry, skip header
        $index = readInt($file);
        if ($index) {
            $start = sizeof($statsList);
            $count = $start;
            fseek($file, $index);
            $w = readString($file);
            while ($w) {
                $statIdx = readInt($file);
                if ($word == substr($w, 0, strlen($word))) {
                    // found word that matches (as substring)
                    $statsList[$count++] = array("word" => $word, "match" => $w, "index" => $statIdx, "full" => strlen($w) == strlen($word), "docs" => array());
                }
                $w = readString($file);
            }
            $totalFreq = 0;
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                fseek($file, $statInfo["index"]);
                $numDocs = readInt($file);
                $docInfo = array();
                // read docs info + occurrence frequency of the word
                $totalFreq = 0;
                for ($i = 0; $i < $numDocs; $i++) {
                    $idx = readInt($file);
                    $freq = readInt($file);
                    $docInfo[$i] = array("idx" => $idx, "freq" => $freq, "rank" => 0.0);
                    $totalFreq += $freq;
                    if ($statInfo["full"]) {
                        $totalFreq += $freq;
                    }
                }
                // read name an url info for the doc
                for ($i = 0; $i < $numDocs; $i++) {
                    fseek($file, $docInfo[$i]["idx"]);
                    $docInfo[$i]["name"] = readString($file);
                    $docInfo[$i]["url"] = readString($file);
                }
                $statInfo["docs"] = $docInfo;
            }
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                for ($i = 0; $i < sizeof($statInfo["docs"]); $i++) {
                    $docInfo =& $statInfo["docs"];
                    // compute frequency rank of the word in each doc
                    $statInfo["docs"][$i]["rank"] = (double) $docInfo[$i]["freq"] / $totalFreq;
                }
            }
        }
    }
    return $statsList;
}
开发者ID:rasata,项目名称:ifimsl,代码行数:57,代码来源:search.php

示例4: clanAllyCrest

function clanAllyCrest($type, $id, $gsId, $crest)
{
    $cacheTime = 3600;
    $path = Yii::getPathOfAlias('webroot.uploads.images.crest') . DIRECTORY_SEPARATOR . $gsId . DIRECTORY_SEPARATOR . $type;
    $filePath = $id . '.png';
    if (!is_dir($path)) {
        if (!mkdir($path, 0777, TRUE)) {
            return '';
        }
    }
    if (!is_file($path . DIRECTORY_SEPARATOR . $filePath) || time() - filemtime($path . DIRECTORY_SEPARATOR . $filePath) >= $cacheTime) {
        // Генерю файл
        $rnd_file = tmpfile();
        fwrite($rnd_file, $crest);
        fseek($rnd_file, 0);
        $file =& $rnd_file;
        //fopen($filename,'rb');
        $dds = fread($file, 4);
        if ($dds !== 'DDS ') {
            return emptyCrest();
        }
        $hdrSize = readInt($file);
        $hdrFlags = readInt($file);
        $imgHeight = readInt($file) - 4;
        $imgWidth = readInt($file);
        $imgPitch = readShort($file);
        fseek($file, 84);
        $dxt1 = fread($file, 4);
        if ($dxt1 !== 'DXT1') {
            return emptyCrest();
        }
        fseek($file, 128);
        //header ("Content-type: image/png");
        $img = imagecreatetruecolor($imgWidth, $imgHeight);
        for ($y = -1; $y < $imgHeight / 4; $y++) {
            for ($x = 0; $x < $imgWidth / 4; $x++) {
                $color0_16 = readShort($file);
                $color1_16 = readShort($file);
                $r0 = $color0_16 >> 11 << 3;
                $g0 = ($color0_16 >> 5 & 63) << 2;
                $b0 = ($color0_16 & 31) << 3;
                $r1 = $color1_16 >> 11 << 3;
                $g1 = ($color1_16 >> 5 & 63) << 2;
                $b1 = ($color1_16 & 31) << 3;
                $color0_32 = imagecolorallocate($img, $r0, $g0, $b0);
                $color1_32 = imagecolorallocate($img, $r1, $g1, $b1);
                $color01_32 = imagecolorallocate($img, $r0 / 2 + $r1 / 2, $g0 / 2 + $g1 / 2, $b0 / 2 + $b1 / 2);
                $black = imagecolorallocate($img, 0, 0, 0);
                $data = readInt($file);
                for ($yy = 0; $yy < 4; $yy++) {
                    for ($xx = 0; $xx < 4; $xx++) {
                        $bb = $data & 3;
                        $data = $data >> 2;
                        switch ($bb) {
                            case 0:
                                $c = $color0_32;
                                break;
                            case 1:
                                $c = $color1_32;
                                break;
                            case 2:
                                $c = $color01_32;
                                break;
                            default:
                                $c = $black;
                                break;
                        }
                        imagesetpixel($img, $x * 4 + $xx, $y * 4 + $yy, $c);
                    }
                }
            }
        }
        imagepng($img, $path . DIRECTORY_SEPARATOR . $filePath);
        imagedestroy($img);
    }
    return '<img src="' . app()->getBaseUrl(TRUE) . '/uploads/images/crest/' . $gsId . '/' . $type . '/' . $filePath . '">';
}
开发者ID:mmorpg2015,项目名称:ghtweb5,代码行数:77,代码来源:lineage.php


注:本文中的readInt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。