有没有办法让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>";
答案 0 :(得分:0)
我使用stristr($ query)来搜索不区分大小写的内容。