Re: Newbie - is there a function similar to the sql 'like' comparisonoperator?
| From: | Shawn McKenzie | Date: | Thu, 08 May 2008 19:13:20 +0000 |
| Subject: | Re: Newbie - is there a function similar to the sql 'like' comparisonoperator? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274037@lists.php.net to get a copy of this message | ||
revDAVE wrote:
Newbie - is there a function similar to the sql 'like' comparison operator? I would like to be able to compare 2 strings: If $this ---*like or similar to*--- $that That type of thing... I know of this page: http://us3.php.net/manual/sl/language.operators.comparison.php But I don't see something 'like' or 'similar' to something else -- Thanks - RevDave Cool @ hosting4days . com [db-lists] Probably the most similar that allows some wildcards (pattern matching) is ereg(). You have more power in that you can control what must match and how much.In MySQL 'a' = ' a ' is true but 'a' LIKE ' a ' is false. So you need to use the wildcard % to match anything ' xxaxx ' LIKE '%a%' is true or _ to match one character ' a ' LIKE '_a_' is true. The problem with similar_text() is that it gives you a percentage of similarity which may be misleading unless you also figure in the return of how many chars match. For example similar_text('CAT', 'CA', &$p) $p would be 66.6%, is that like or not? -Shawn