Michal
Michal

Reputation: 2039

Fulltext search in PHP

I want to perform fulltext search for a given phrase in a given string using PHP.

I want this search to be:

Can you help me? ...I am sorry for creating new post, I've searched a lot, before I asked. However, I found only posts that concerned with PHP+MySQL search.

Upvotes: 1

Views: 5223

Answers (3)

Supun Kavinda
Supun Kavinda

Reputation: 1493

How MYSQL Full-Text Search work is complex compared to PHP preg match. For example, stop words are considered in MYSQL full text search.

If you only need to depend on PHP, (and no libraries) you will need to do some development. Here's a popular library created like that.

Upvotes: 2

stepozer
stepozer

Reputation: 1191

For full text search i know 2 common solutions:

  1. Use MYISAM FULLTEXT index http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html

So, if you have InnoDB table, you must copy searchable info into MYISAM table (for example use triggers)

  1. Use external special search engines. For example:

Upvotes: 0

Stanislav Komanec
Stanislav Komanec

Reputation: 49

You have to remove diacritics from string and then need to use preg_match

<?php
// The "i" after the pattern delimiter indicates a case-insensitive search
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}
?>

PHP documentation: http://php.net/manual/en/ref.pcre.php

Upvotes: 1

Related Questions