1 回答

TA貢獻1942條經驗 獲得超3個贊
您可以使用 fullMatch 正則表達式和 fullMatch 標志嘗試類似的操作。
如果找到完全匹配,則觸發標志 fullMatch,然后在搜索中只能找到完全匹配
// Make Regex e.g. '/Project|Name/i' means 'Project or Name' case (i)nsensitive
$regex = '#' . implode( '|', $words ) . '#i';
$regexFullMatch = '#' . implode( '', $words ) . '#i';
$isFullMatched = true;
.
.
.
if ( preg_match( $regex, $Job_Name ) && $Time_Complete == '' ) {
if(preg_match( $regexFullMatch, $Job_Name )){
// Show Data in Browser
echo '
<div class="box">' . $Time_Started . '</div>
<div class="box">' . $Details_3 . '</div>
<div class="box">' . $Job_Name . '</div>
<div class="box noBorder"><a class="update"
href="' . htmlentities($_SERVER['PHP_SELF']) . '?update=' .
htmlentities( urlencode( $Job_Name ) ) . '">' .
$txt_completebutton . '</a></div><br>
';
// Set Search-Hit Helper
$hit = true;
$isFullMatched = true;
}
else if(!$isFullMatched){
// Show Data in Browser
echo '
<div class="box">' . $Time_Started . '</div>
<div class="box">' . $Details_3 . '</div>
<div class="box">' . $Job_Name . '</div>
<div class="box noBorder"><a class="update"
href="' . htmlentities($_SERVER['PHP_SELF']) . '?update=' .
htmlentities( urlencode( $Job_Name ) ) . '">' .
$txt_completebutton . '</a></div><br>
';
// Set Search-Hit Helper
$hit = true;
}
}
注意:這段代碼沒有優化,但它給了你一個想法!
- 1 回答
- 0 關注
- 118 瀏覽
添加回答
舉報