Example #1
0
 public static function cutString($str, $len, $more)
 {
     if ($str == "" || $str == NULL) {
         return $str;
     }
     if (is_array($str)) {
         return $str;
     }
     $str = strip_tags($str, '');
     $str = trim($str);
     if (mb_strlen($str) <= $len) {
         return $str;
     }
     $str = mb_substr($str, 0, $len);
     if ($str != "") {
         if (!mb_substr_count($str, " ")) {
             if ($more) {
                 $str .= " ...";
             }
             return $str;
         }
         while (mb_strlen($str) && $str[mb_strlen($str) - 1] != " ") {
             $str = mb_substr($str, 0, -1);
         }
         $str = mb_substr($str, 0, -1);
         if ($more) {
             $str .= " ...";
         }
     }
     return $str;
 }
Example #2
0
 function cut($text, $lenght = 250)
 {
     $text = html_entity_decode($text);
     $text = preg_replace("/" . self::$fakeSymb . "/", "", $text);
     //move all tags to array tags
     $text = preg_replace("/(<\\/?)(\\w+)([^>]*>)/e", "html_cutter::tagOut('\\0')", $text);
     //check how many tags in cutter text to fix cut length
     $preCut = mb_substr($text, 0, $lenght);
     $fakeCount = mb_substr_count($preCut, self::$fakeSymb);
     //cut string
     $text = mb_substr($text, 0, $lenght + $fakeCount * mb_strlen(self::$fakeSymb));
     //remove last word
     $text = preg_replace("/\\S*\$/", "", $text);
     //return tags back
     self::$tagCounter = 0;
     $text = preg_replace("/" . self::$fakeSymb . "/e", "html_cutter::tagIn()", $text);
     //get count not closed tags
     $closeCount = count(self::$openTags) - count(self::$closeTags);
     //close opened tags
     for ($i = 0; $i < $closeCount; $i++) {
         $tagName = array_pop(self::$openTags);
         $text .= "</{$tagName}>";
     }
     return $text;
 }
Example #3
0
 public function testCodeWithEmbedOnPsc()
 {
     $this->assertContains("requireLoad(", $code = (string) $this->createSnippet('no code', array())->loadOnPscReady(TRUE)->html());
     $this->assertContains('<script type="text/javascript"', $code);
     // nicht 2 script tags
     $this->assertEquals(1, mb_substr_count($code, '</script>'));
 }
 public function apply($value)
 {
     if (mb_check_encoding($value, 'UTF-16') && mb_substr_count($value, "") > 0) {
         $value = mb_convert_encoding($value, 'UTF-8', 'UTF-16');
     }
     return $value;
 }
Example #5
0
 /**
  * Configure the feature with a single string
  *
  * Format of config string should be: "100|1,2,3,4|ROLE_ADMIN,ROLE_PREMIUM|caretaker,supporter,staff"
  * - where "100" is the percentage of user for that the feature should be enabled.
  * - where "1,2,3,4" are a comma-separated list of user IDs that should have this feature.
  * - where "ROLE_ADMIN,ROLE_PREMIUM" are a comma-separated list of the role names that should have this feature.
  * - where "caretaker,supporter,staff" are a comma-separated list of the role names that should have this feature.
  *
  * Empty section are allowed and silently ignored as long as the format of the string stays the same:
  * e.g. "20||ROLE_PREMIUM|" is valid (20 percent and additionally al users with ROLE_PREMIUM will get the feature)
  * e.g. "|||" is valid and will completely disable this feature, but it is recommend to use "0|||" instead.
  *
  * @param string $configString
  * @return bool Successfully parsed the config string or not
  */
 public function configureByConfigString($configString)
 {
     $successsfullyConfigured = false;
     if (true === is_string($configString) && '' !== $configString && 3 === mb_substr_count($configString, self::FEATURE_CONFIGSTRING_SECTION_DELIMITER)) {
         list($percentageString, $usersString, $rolesString, $groupsString) = explode(self::FEATURE_CONFIGSTRING_SECTION_DELIMITER, $configString);
         $this->setPercentage((int) 0);
         if (true === is_numeric($percentageString)) {
             $this->setPercentage((int) $percentageString);
         }
         $this->setUsers(array());
         if (true === is_string($usersString) && '' !== $usersString) {
             $userIds = explode(self::FEATURE_CONFIGSTRING_ENTRY_DELIMITER, $usersString);
             $this->setUsers($userIds);
         }
         $this->setRoles(array());
         if (true === is_string($rolesString) && '' !== $rolesString) {
             $roleNames = explode(self::FEATURE_CONFIGSTRING_ENTRY_DELIMITER, $rolesString);
             $this->setRoles($roleNames);
         }
         $this->setGroups(array());
         if (true === is_string($groupsString) && '' !== $groupsString) {
             $groupNames = explode(self::FEATURE_CONFIGSTRING_ENTRY_DELIMITER, $groupsString);
             $this->setGroups($groupNames);
         }
         $successsfullyConfigured = true;
     }
     return $successsfullyConfigured;
 }
Example #6
0
function display_compile_output($output, $success)
{
    $color = "#6666FF";
    $msg = "not finished yet";
    if ($output !== NULL) {
        if ($success) {
            $color = '#1daa1d';
            $msg = 'successful';
            if (!empty($output)) {
                $msg .= ' (with ' . mb_substr_count($output, "\n") . ' line(s) of output)';
            }
        } else {
            $color = 'red';
            $msg = 'unsuccessful';
        }
    }
    echo '<h3 id="compile">' . (empty($output) ? '' : "<a class=\"collapse\" href=\"javascript:collapse('compile')\">") . "Compilation <span style=\"color:{$color};\">{$msg}</span>" . (empty($output) ? '' : "</a>") . "</h3>\n\n";
    if (!empty($output)) {
        echo '<pre class="output_text" id="detailcompile">' . specialchars($output) . "</pre>\n\n";
    } else {
        echo '<p class="nodata" id="detailcompile">' . "There were no compiler errors or warnings.</p>\n";
    }
    // Collapse compile output when compiled succesfully.
    if ($success) {
        echo "<script type=\"text/javascript\">\n<!--\n\tcollapse('compile');\n// -->\n</script>\n";
    }
}
 public function execute()
 {
     if ($this->isCaseInsensitive()) {
         return mb_substr_count(mb_strtolower($this->getValue()), mb_strtolower($this->needle));
     } else {
         return mb_substr_count($this->getValue(), $this->needle);
     }
 }
Example #8
0
function figure_count($texts)
{
    global $figure;
    $figcnt = 0;
    foreach ($texts as $text_line) {
        $figcnt += mb_substr_count($text_line, $figure);
    }
    return $figcnt;
}
 /**
  * @see \wcf\system\bbcode\IBBCode::getParsedTag()
  */
 public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser)
 {
     // copyright
     TeraliosBBCodesCopyright::callCopyright();
     $content = StringUtil::trim($content);
     if (!empty($content) || mb_strpos($content, '[.]') !== false && mb_strpos($content, '[:]') !== false) {
         $content = str_replace('[.]', '[*]', $content);
         // build main list elements
         $listElements = preg_split('#\\[\\*\\]#', $content, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($listElements as $key => $val) {
             $val = StringUtil::trim($val);
             if (empty($val) || $val == '<br />') {
                 unset($listElements[$key]);
             } else {
                 $listElements[$key] = $val;
             }
         }
         // build list
         if (!empty($listElements)) {
             $listContent = '';
             foreach ($listElements as $point) {
                 if (mb_substr_count($point, '[:]') == 1) {
                     // reset key and value.
                     $key = $value = '';
                     // split list element on [:] in key and definition of key.
                     list($key, $value) = preg_split('#\\[:\\]#', $point, -1);
                     $key = StringUtil::trim($key);
                     $value = StringUtil::trim($value);
                     if (empty($value)) {
                         $value = WCF::getLanguage()->get('wcf.bbcode.dlist.noDefinition');
                     }
                     // key is not empty.
                     if (!empty($key)) {
                         if ($parser->getOutputType() == 'text/html') {
                             $listContent .= '<dt>' . $key . '</dt><dd>' . $value . '</dd>';
                         } else {
                             if ($parser->getOutputType() == 'text/simplified-html') {
                                 $listContent .= '*' . $key . ': ' . $value . "\n";
                             }
                         }
                     }
                 }
             }
             if (!empty($listContent)) {
                 if ($parser->getOutputType() == 'text/html') {
                     return '<dl class="dlistBBCode">' . $listContent . '</dl><span></span>';
                 } else {
                     if ($parser->getOutputType() == 'text/simplified-html') {
                         return $listContent;
                     }
                 }
             }
         }
     }
     return '[dlist]' . $content . '[/dlist]';
 }
Example #10
0
 function _check_language()
 {
     $serverName = $this->request->serverName;
     //语言与当前浏览器设置有关
     $lan = $this->request->preferredLanguage;
     if (mb_substr_count($serverName, '.') == 2) {
         $lan = substr($serverName, 0, strpos($serverName, '.'));
     }
     Yii::app()->language = $lan;
 }
Example #11
0
 public function __construct($tldCheck = true)
 {
     $this->checks[] = new NoWhitespace();
     $this->checks[] = new Contains('.');
     $this->checks[] = new Length(3, null);
     $this->tldCheck($tldCheck);
     $this->otherParts = new AllOf(new Alnum('-'), new Not(new StartsWith('-')), new OneOf(new Not(new Contains('--')), new AllOf(new StartsWith('xn--'), new Callback(function ($str) {
         return mb_substr_count($str, '--') == 1;
     }))));
 }
 public function testShorting()
 {
     $searchWord = 'für';
     $h = new Kwf_View_Helper_HighlightTerms();
     $res = $h->highlightTerms($searchWord, $this->_text, array('maxReturnLength' => 200, 'maxReturnBlocks' => 4));
     $highlights = mb_substr_count($res, '<span ');
     $this->assertEquals(4, $highlights);
     $highlights = mb_substr_count($res, ' ... ');
     $this->assertEquals(3, $highlights);
     $this->assertLessThanOrEqual(200, mb_strlen(strip_tags($res)));
 }
Example #13
0
 /**
  * @param $query_string String
  * @return Array
  */
 private function _queryToArray($query_string)
 {
     $result = [];
     if (mb_substr_count($query_string, '=')) {
         foreach (explode('&', $query_string) as $couple) {
             list($key, $val) = explode('=', $couple);
             $result[$key] = $val;
         }
     }
     return empty($result) ? false : $result;
 }
Example #14
0
function frutCounter($string)
{
    $string = str_replace(PHP_EOL, " ", $string);
    $arr = array_unique(array_filter(explode(" ", $string)));
    $frutArrSorted = array();
    foreach ($arr as $v) {
        $v = trim($v);
        $frutArrSorted[$v] = mb_substr_count($string, $v);
    }
    array_multisort($frutArrSorted, SORT_DESC);
    return $frutArrSorted;
}
Example #15
0
 /**
  * Parses an amount's decimal separator.
  *
  * @param string $amount
  *   Any optionally localized numeric value.
  *
  * @return string|false
  *   The amount with its decimal separator replaced by a period, or FALSE in
  *   case of failure.
  */
 protected function parseAmountDecimalSeparator($amount)
 {
     $decimal_separator_counts = [];
     foreach ($this->decimalSeparators as $decimal_separator) {
         $decimal_separator_counts[$decimal_separator] = \mb_substr_count($amount, $decimal_separator);
     }
     $decimal_separator_counts_filtered = array_filter($decimal_separator_counts);
     if (count($decimal_separator_counts_filtered) > 1 || reset($decimal_separator_counts_filtered) !== FALSE && reset($decimal_separator_counts_filtered) != 1) {
         return FALSE;
     }
     return str_replace($this->decimalSeparators, '.', $amount);
 }
Example #16
0
function countWords($text)
{
    $text = mb_strtolower($text);
    $wordArr = explode(" ", $text);
    $uniqueCount = 0;
    foreach ($wordArr as $v) {
        if (mb_strlen($v) and mb_substr_count($text, $v) == 1) {
            $uniqueCount++;
        }
    }
    return $uniqueCount;
}
Example #17
0
/**
 * Smarty {math} function plugin
 *
 * Type:     function<br>
 * Name:     math<br>
 * Purpose:  handle math computations in template<br>
 * @link http://smarty.php.net/manual/en/language.function.math.php {math}
 *          (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_math($params, &$smarty)
{
    // be sure equation parameter is present
    if (empty($params['equation'])) {
        $smarty->trigger_error("math: missing equation parameter");
        return;
    }
    // strip out backticks, not necessary for math
    $equation = str_replace('`', '', $params['equation']);
    // make sure parenthesis are balanced
    if (mb_substr_count($equation, "(") != mb_substr_count($equation, ")")) {
        $smarty->trigger_error("math: unbalanced parenthesis");
        return;
    }
    // match all vars in equation, make sure all are passed
    preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
    $allowed_funcs = array('int', 'abs', 'ceil', 'cos', 'exp', 'floor', 'log', 'log10', 'max', 'min', 'pi', 'pow', 'rand', 'round', 'sin', 'sqrt', 'srand', 'tan');
    foreach ($match[1] as $curr_var) {
        if ($curr_var && !in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
            $smarty->trigger_error("math: function call {$curr_var} not allowed");
            return;
        }
    }
    foreach ($params as $key => $val) {
        if ($key != "equation" && $key != "format" && $key != "assign") {
            // make sure value is not empty
            if (mb_strlen($val) == 0) {
                $smarty->trigger_error("math: parameter {$key} is empty");
                return;
            }
            if (!is_numeric($val)) {
                $smarty->trigger_error("math: parameter {$key}: is not numeric");
                return;
            }
            $equation = preg_replace("/\\b{$key}\\b/", " \$params['{$key}'] ", $equation);
        }
    }
    eval("\$smarty_math_result = " . $equation . ";");
    if (empty($params['format'])) {
        if (empty($params['assign'])) {
            return $smarty_math_result;
        } else {
            $smarty->assign($params['assign'], $smarty_math_result);
        }
    } else {
        if (empty($params['assign'])) {
            printf($params['format'], $smarty_math_result);
        } else {
            $smarty->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
        }
    }
}
Example #18
0
 /**
  * getMostFrequentNeedle by counting occurences of each needle in haystack.
  *
  * @param string $haystack Haystack to be searched in.
  * @param array  $needles  Needles to be counted.
  *
  * @return string|null The most occuring needle. If counts are tied, the first tied needle is returned. If no
  *                     needles were found, `null` is returned.
  */
 public static function getMostFrequentNeedle($haystack, array $needles)
 {
     $maxCount = 0;
     $maxNeedle = null;
     foreach ($needles as $needle) {
         $newCount = mb_substr_count($haystack, $needle);
         if ($newCount > $maxCount) {
             $maxCount = $newCount;
             $maxNeedle = $needle;
         }
     }
     return $maxNeedle;
 }
Example #19
0
 /**
  * Parses an amount's decimal separator.
  *
  * @throws AmountInvalidDecimalSeparatorException
  *
  * @param string $amount
  *   Any optionally localized numeric value.
  *
  * @return string
  *   The amount with its decimal separator replaced by a period.
  */
 public static function parseAmountDecimalSeparator($amount)
 {
     $decimal_separator_counts = array();
     foreach (self::$decimalSeparators as $decimal_separator) {
         $decimal_separator_counts[$decimal_separator] = \mb_substr_count($amount, $decimal_separator);
     }
     $decimal_separator_counts_filtered = array_filter($decimal_separator_counts);
     if (count($decimal_separator_counts_filtered) > 1 || reset($decimal_separator_counts_filtered) !== FALSE && reset($decimal_separator_counts_filtered) != 1) {
         throw new AmountInvalidDecimalSeparatorException(strtr('The amount can only have no or one decimal separator and it must be one of "decimalSeparators".', array('decimalSeparators' => implode(self::$decimalSeparators))));
     }
     $amount = str_replace(self::$decimalSeparators, '.', $amount);
     return $amount;
 }
Example #20
0
function filter_number_format($Number)
{
    global $DecimalPoint;
    global $ThousandsSeparator;
    $SQLFormatNumber = str_replace($DecimalPoint, '.', str_replace($ThousandsSeparator, '', trim($Number)));
    /*It is possible if the user entered the $DecimalPoint as a thousands separator and the $DecimalPoint is a comma that the result of this could contain several periods "." so need to ditch all but the last "." */
    if (mb_substr_count($SQLFormatNumber, '.') > 1) {
        return str_replace('.', '', mb_substr($SQLFormatNumber, 0, mb_strrpos($SQLFormatNumber, '.'))) . mb_substr($SQLFormatNumber, mb_strrpos($SQLFormatNumber, '.'));
        echo '<br /> Number of periods: ' . $NumberOfPeriods . ' $SQLFormatNumber = ' . $SQLFormatNumber;
    } else {
        return $SQLFormatNumber;
    }
}
Example #21
0
File: z.php Project: keyzf/z.js
function z($d, $p = false, $m = false)
{
    /*RC4 implementation*/
    if (!function_exists('rc4')) {
        function rc4($d, $p)
        {
            if (!$p) {
                return $d;
            }
            $a = array();
            $j = 0;
            for ($i = 0; $i < 256; $i++) {
                $a[$i] = $i;
            }
            for ($i = 0; $i < 256; $i++) {
                $j = ($j + $a[$i] + ord($p[$i % strlen($p)])) % 256;
                $z = $a[$i];
                $a[$i] = $a[$j];
                $a[$j] = $z;
            }
            $i = $j = 0;
            for ($y = 0; $y < strlen($d); $y++) {
                $i = ($i + 1) % 256;
                $j = ($j + $a[$i]) % 256;
                $z = $a[$i];
                $a[$i] = $a[$j];
                $a[$j] = 0 + $z;
                @($R .= $d[$y] ^ chr($a[($a[$i] + $a[$j]) % 256]));
            }
            return $R;
        }
    }
    $a = array(json_decode('"\\u200c"'), json_decode('"\\u200d"'), !is_bool($m) ? $m[0] : json_decode('"\\u2589"'));
    $A = str_repeat($a[0], 32) . str_repeat($a[1], 32);
    if (@$m[1] && mb_substr_count($d, $m[1]) % 2 == 0) {
        //parts-mode
        return preg_replace_callback("#\\{$m[1]}([\\x{0000}-\\x{ffff}]+?)\\{$m[1]}#ums", function ($_) use($A, $p, $m) {
            return $A . z($_[1], $p ? $p : !1, $m[0]);
        }, preg_replace("#\\{$m[1]}{2}#ums", '', $d));
    }
    if ($m) {
        $m = preg_replace('# {2,}#ms', ' ', preg_replace('#[^ \\t\\n]#ums', $a[2], html_entity_decode('' . strip_tags($d), !1, 'UTF-8')));
    }
    $d = rc4("ÿÿÿÿ" . preg_replace_callback('#[\\x{0100}-\\x{ffff}]#u', function ($_) {
        return '&#' . hexdec(json_encode($_[0])) . ';';
    }, $d), $p);
    for ($j = 0; $j < strlen($d); $j++) {
        @($z .= str_replace(array(0, 1), $a, str_pad(decbin(ord($d[$j])), 8, '0', STR_PAD_LEFT)));
    }
    return ($m ? $a[2] : '') . $z . @mb_substr($m, 1);
}
Example #22
0
function filter_string()
{
    $string = $_POST['string'];
    $remaining = "";
    for ($i = 0; $i < mb_strlen($string, encoding); $i++) {
        $char = mb_substr($string, $i, 1, encoding);
        $isRepeating = mb_substr_count($string, $char, encoding) > 1;
        $repeatsFirst = mb_substr_count($remaining, $char, encoding) <= 0;
        if ($isRepeating && $repeatsFirst) {
            $remaining .= " " . $char;
        }
    }
    echo $remaining;
}
 private function sendPublic(UserCollection $clients, User $user, $msg, $isSelf)
 {
     $props = $user->getProperties();
     $filteredMsg = RudeFilter::parse($msg);
     if (mb_strlen($filteredMsg) != mb_strlen($msg)) {
         $props->setRudeCount($props->getRudeCount() + 1);
     }
     $props->setWordsCount($props->getWordsCount() + mb_substr_count($msg, ' ') + 1);
     $response = (new MessageResponse())->setMsg(Msg::create($msg))->setFilteredMsg(Msg::create($filteredMsg))->setTime(null)->setChannelId($user->getChannelId());
     if (!$isSelf) {
         $response->setFrom($user);
     }
     $clients->setResponse($response)->notify();
 }
Example #24
0
 public function testNormalize()
 {
     $content = @file_get_contents('./tests/mocks/toBeNormalized.txt');
     $normalizer = Normalizer::fromString($content);
     $normalized = $normalizer->getText();
     $lineBreaks = mb_substr_count($normalized, "\n");
     $spaces = mb_substr_count($normalized, " ");
     $tabs = mb_substr_count($normalized, "\t");
     $lines = count($normalizer->getLines());
     $this->assertEquals(6, $lineBreaks);
     $this->assertEquals(33, $spaces);
     $this->assertEquals(0, $tabs);
     $this->assertEquals(7, $lines);
 }
Example #25
0
function title($prefix, $main, $suffix)
{
    if (strlen($main) >= 70 || mb_substr_count($main, " ") > 11) {
        return $main;
    }
    $title = $prefix . "|" . $main;
    if (strlen($title) >= 70 || mb_substr_count($title, " ") > 11) {
        return $main;
    }
    $tmp_title = $title . "|" . $suffix;
    if (mb_substr_count($tmp_title, " ") < 11 && strlen($tmp_title) <= 70) {
        $title = $tmp_title;
    }
    return $title;
}
 /**
  * 显示位列表
  * @param HttpRequest $request
  */
 public function index(HttpRequest $request)
 {
     parent::index($request);
     //获取文章数量
     $items = $this->getTemplateVar('items');
     foreach ($items as $key => $value) {
         if ($value['aids'] == '') {
             $items[$key]['art_num'] = 0;
         } else {
             $items[$key]['art_num'] = mb_substr_count($value['aids'], ',') + 1;
         }
     }
     $this->assign('items', $items);
     $this->setView('artone/position_index');
 }
Example #27
0
 public static function parseFloat($floatString, $thousandsSep = self::USE_LOCALE, $decimalPoint = self::USE_LOCALE)
 {
     $locale = localeconv();
     if ($thousandsSep === self::USE_LOCALE) {
         $thousandsSep = $locale['mon_thousands_sep'];
     }
     if ($decimalPoint === self::USE_LOCALE) {
         $decimalPoint = $locale['mon_decimal_point'];
     }
     if (mb_substr_count($floatString, ',') > 1) {
         throw new \Psc\Exception('Parsing von ' . $data . ' war nicht möglich. Mehr als ein Komma vorhanden!');
     }
     $floatString = str_replace(array($thousandsSep, $decimalPoint), array('', '.'), $floatString);
     return floatval($floatString);
 }
 public function next()
 {
     if ($this->valid()) {
         $token = $this->current();
         if ($token->isGivenKind([T_WHITESPACE, T_OPEN_TAG, T_COMMENT, T_DOC_COMMENT]) && ($n = strpos($token->getContent(), "\n")) !== false) {
             $this->lineNumber += mb_substr_count($token->getContent(), "\n");
             $this->columnNumber = mb_strlen(substr($token->getContent(), $n + 1));
             if ($this->columnNumber === 0) {
                 $this->columnNumber = 1;
             }
         } else {
             $this->columnNumber += mb_strlen($token->getContent());
         }
     }
     parent::next();
 }
Example #29
0
function fileList($dirName, $word)
{
    $dirPath = __DIR__ . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR;
    $word = mb_strtolower($word);
    if (is_dir($dirPath)) {
        $dirArr = scandir($dirPath);
        foreach ($dirArr as $k => $v) {
            if (is_file($dirPath . $dirArr[$k])) {
                $text = mb_strtolower(file_get_contents($dirPath . $dirArr[$k]));
                if (mb_substr_count($text, $word)) {
                    echo $v . "<br>";
                }
            }
        }
    }
}
Example #30
0
 public function crawl()
 {
     echo 'starting crawl...', PHP_EOL;
     echo date('Y-m-d H:i:s'), PHP_EOL;
     $times = 0;
     $last_update = time();
     try {
         $stream = fopen(sprintf('http://%s:%s@stream.twitter.com/1/statuses/sample.json', def('twitter_account'), def('twitter_password')), 'r');
         while ($json = fgets($stream)) {
             $status = json_decode($json, true);
             if (!isset($status['text'])) {
                 continue;
             }
             $text = $status['text'];
             $times += substr_count($text, '!');
             $times += mb_substr_count($text, '!');
             if ($times > 0 && time() - def('update_span', 180) > $last_update) {
                 try {
                     $counter = new BibitterCounter();
                     $counter->times($times);
                     $counter->save();
                     C($counter)->commit();
                     unset($counter);
                 } catch (Exception $e) {
                     echo $e->getMessage(), PHP_EOL;
                     Log::d($counter);
                     exit;
                     continue;
                 }
                 Log::debug(sprintf('updated: %d times on %s.', $times, date('Y-m-d H:i:s')));
                 Log::flush();
                 $times = 0;
                 $last_update = time();
             }
         }
     } catch (Exception $e) {
         echo $e->getMessage(), PHP_EOL;
     }
     Log::flush();
     echo 'disconnected...', PHP_EOL;
     echo date('Y-m-d H:i:s'), PHP_EOL;
     for ($wait = 30; $wait > 0; $wait--) {
         sleep(1);
         echo 'recconect wait ' . $wait . ' sec', PHP_EOL;
     }
     $this->crawl();
 }