1

検索結果を次のようなものにするにはどうすればよいでしょうか: http://i.stack.imgur.com/NfPGs.png

結果は、特定の用語がセル内のどこにあるかを示します。

私は現在、この基本的な検索スクリプトを持っています:

      $terms = explode("-", $SQuery);
    $QuerySQL = "SELECT * FROM pages WHERE ";

        foreach ($terms as $each){
        $i++;

        if ($i == 1)
            $QuerySQL .= "Title LIKE '%$each%' OR Content LIKE '%$each%' OR Description LIKE '%$each%'";
        else 
            $QuerySQL .= "OR Title LIKE '%$each%' OR Description LIKE '%$each%' OR Content LIKE '%$each%'";
        }

    $QueryNEW = mysql_query($QuerySQL);

WHILE($datarows_cat = mysql_fetch_array($QueryNEW)):

        $title = $datarows_cat['Title'];
        $Deleted = $datarows_cat['Deleted'];
        $id = $datarows_cat['ID'];
        if ($Deleted != "YES") {
        echo "<a href='/{$id}'>{$title}</a><br/>";

}
4

1 に答える 1

0

PHP strposを使用して、+/- 100 文字を検索できます。

$pos = strpos($mystring, $findme);

if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}

次に、PHP substr$pos+100を使用して、およびの部分文字列を取得します。$pos-100

//For instance your substring could start at the position of the word found minus 100 characters and a length of 200
$result = substr($mystring, $pos-100, 200);

PHP str_replaceを使用して、必要な文字列をフォーマットできます。

$word_your_looking_for = "test";
$word_you_want_to_replace_it_with = "<b>test</b>"; //Make it bold

str_replace($word_your_looking_for, $word_you_want_to_replace_it_with, $your_string);
于 2013-02-18T19:58:11.110 に答える