簡體   English   中英

PHP搜索大寫和小寫字母

[英]PHP Search Upper and Lowercase letters

有沒有一種方法可以使PHP搜索並返回結果,無論大小寫字母是否不同。 我當前的代碼進行搜索,僅返回大寫和小寫的確切結果。 所以我都將其全部小寫,但是我希望結果中的名稱具有正確的大寫字母。

通過LDAP搜索。 值是來自Active Directory的信息,搜索是在搜索人的姓名,並給出該人的電話號碼等結果

這是我的代碼:

// Address Book Search
$search .= "<div class='border'>\n";
$search .= "<h1>Search for Staff</h1>";
$search .= '<form class="search-form-wrapper" method="GET">
                <input type="text" name="q" id="search" placeholder="Search for Staff..." required>
                <input type="submit" value="go" id="submit">
            </form><br><br>';

if (count($staff)) {
    if (isset($_GET['q'])) {
        $query = strip_tags($_GET['q']);
        $query = str_replace('%27', "'", $query);
        $query = strtolower($query);
        $search .= "<table class='address_book'><tr><th>Name</th><th>Title</th><th>Phone</th><th>Mobile</th><th>Email</th><th>Dept</th></tr>\n";
        foreach ($staff as $key => $details) {
            $details['displayname'] = strtolower($details['displayname']);
            if(substr_count($details['displayname'], $query)){
            $search .= "<tr><td>{$details['displayname']}</td>\n";
            $search .= "<td>{$details['title']}</td>\n";
            $search .= "<td>{$details['telephonenumber']}</td>\n";
            $search .= "<td>{$details['mobile']}</td>\n";
            $search .= "<td><a href='mailto:{$details['mail']}'>{$details['mail']}</a></td>\n";
            $search .= "<td>{$details['department']}</td>\n";
            $search .= "</tr>\n";
            }
        }
        $search .= "</table>\n";
    }
}
$search .= "</div><br>";

我使用stristr($ query)搜索不區分大小寫的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM