Forum Moderators: coopster

Message Too Old, No Replies

How to find a string in array values?

Like you can in a sql statement using LIKE

         

HughMungus

1:18 am on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm setting up a database search and want to be able to find strings that are part of an array value.

For example, if my database has "cats, dogs, goats" and someone uses "cat" as the search query, I want "cats" to be found in the array.

I know you can use in_array for EXACT matches but is there a way to find LIKE-type matches in values in an array?

TIA

jatar_k

1:26 am on May 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



select * from table where col like '%cats%'

take a look here
MySQL String Comparison Functions [dev.mysql.com]

Netizen

1:32 pm on May 13, 2004 (gmt 0)

10+ Year Member



If you want to find it in array values try preg_grep [php.net].

[Not used it myself]

HughMungus

10:29 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops, sorry Jatar, I meant on an array, not on a sql query. I know how to do it in a sql query, but was wondering if there was a way to get a non-exact match in an array search (e.g., using in_array).

HughMungus

10:31 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Netizen. I'll check it out.