Question
March 9, 2007 at 07:43 PM
giantsand98

How to find EXACT matches with preg_grep

by giantsand98 . Updated 19 years, 6 months ago

I am storing a list of favorites as a string (i.e. 12,54,75,55,155) and I am trying to write a function that will delete a selected id from that string.

I thought of using preg_grep with preg_grep_invert to get everything back except the chosen id and write that back to the db. This works except for one thing…

In the example above, if I pass id 55 to the function, preg_grep views anything with 55 in it as a match even if it’s only a partial match (i.e. 55 and 155).

How can I restrict this to exact matches only? If not with preg_grep, is there another way to do this?

This discussion is locked

All Comments