简体   繁体   English

PHP搜索大写和小写字母

[英]PHP Search Upper and Lowercase letters

Is there a way to get PHP to search and come back results no matter the difference of upper or lowercase letters. 有没有一种方法可以使PHP搜索并返回结果,无论大小写字母是否不同。 My current code searches and only comes back with exact results of upper and lower case. 我当前的代码进行搜索,仅返回大写和小写的确切结果。 So i made it all lowercase, but i want the results to have the correct uppercase letters for names. 所以我都将其全部小写,但是我希望结果中的名称具有正确的大写字母。

It's searching via LDAP. 通过LDAP搜索。 The values are information from Active Directory, the search is searching the names of people, and giving the results such as Phone Number etc of that person 值是来自Active Directory的信息,搜索是在搜索人的姓名,并给出该人的电话号码等结果

Here is my code: 这是我的代码:

// 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