Making a relevant search of text in database using regex

Posted by madphp on Stack Overflow See other posts from Stack Overflow or by madphp
Published on 2011-02-16T16:16:05Z Indexed on 2011/02/16 23:25 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

Can anyone tell me how I could count the possible instances of a keyword in a block of text?
I've split a search term up into separate tokens, so just need to run through and do a count for every instance and removing punctuation or other special characters when making the count.

Secondly, if someone has inserted search terms surrounded by double quotes, i want to be able to skip explode, but just count instances of that exact phrase. It doesn't have to be case sensitive and I would like to remove punctuation from the phrase when doing the count.

Thirdly, in both cases i want to be able to ignore wordpress and html tags.

Lastly, if anyone know any good tutorials for relevant searches that answer the questions above, that would cool too.

I've got this far.

$results = $wpdb->get_results($sql);

    $tokens = explode('search_terms');

    // Re-arrange Relevant Results
    foreach ($results As $forum_topic){

        foreach($tokens As $token){

            // count tokens in topic_title
            if ($token ){

            }

        }

    }

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql