【问题标题】:Minimum 4 Characters or Show Nothing - PHP最少 4 个字符或不显示任何内容 - PHP
【发布时间】:2011-01-28 03:11:31
【问题描述】:

我只想显示最少 4 个字符的单词,实际上我可以限制命中并仅显示带有 min 的单词。 100 次点击 - 但我怎样才能设置分钟。字符长度?谢谢!

function sm_list_recent_searches($before = '', $after = '', $count = 20) {
// List the most recent successful searches.
    global $wpdb, $table_prefix;
    $count = intval($count);
    $results = $wpdb->get_results(
        "SELECT `terms`, `datetime`
        FROM `{$table_prefix}searchmeter_recent`
        WHERE 100 < `hits`
        ORDER BY `datetime` DESC
        LIMIT $count");
    if (count($results)) {

        foreach ($results as $result) {
            echo '<a href="'. get_settings('home') . '/search/' . urlencode($result->terms) . '">'. htmlspecialchars($result->terms) .'</a>'.", ";
        }

    }
}

【问题讨论】:

    标签: php character-limit


    【解决方案1】:

    来自MySql manual

    CHAR_LENGTH(str) 返回字符串 str 的长度,以字符为单位。多字节字符计为单个字符。这意味着对于包含五个 2 字节字符的字符串,LENGTH() 返回 10,而 CHAR_LENGTH() 返回 5。

    所以你添加

    where(char_length(terms) > 4))
    

    【讨论】:

      【解决方案2】:

      如果您使用的是 mySQL:

      WHERE 100 < `hits` AND CHAR_LENGTH('yourField') > 4
      

      【讨论】:

      • 加上这个,因为它是第一个,我将长度与 char_length 混合在一起
      猜你喜欢
      • 1970-01-01
      • 2020-03-04
      • 2011-04-17
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      • 2012-09-29
      相关资源
      最近更新 更多