dreamwest Posted January 29, 2011 Share Posted January 29, 2011 So i have i simple string of numbers but want to match both numbers, "|" wont work because it matches either number $string = "567 6776 6656 77"; How can i match both number "567" and "77" within the $string? Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted January 29, 2011 Share Posted January 29, 2011 Your best option would be to explode() the string then use array_search to check for both values $arr = explode(' ', $string); if(in_array('567', $arr) && in_array('777', $arr)) { // TRUE } else { // FALSE } Quote Link to comment Share on other sites More sharing options...
dreamwest Posted January 29, 2011 Author Share Posted January 29, 2011 Problem is the sting is in the database so ive gotta try and get it into a query Something like this checks either number $ids = "(567|7878)"; SELECT `id` FROM `video` WHERE `word_id` REGEXP '[[:<:]]{$ids}[[:>:]]' = 1 The fields look like this id word_id (VARCHAR 255) 1 567,676,7878 2 123,543,34 3 567,75,87 I checked wiki , apparently it can be done http://en.wikipedia.org/wiki/Regular_expression Quote Link to comment Share on other sites More sharing options...
sasa Posted January 30, 2011 Share Posted January 30, 2011 try $ids = "(567|7878)"; $sql = 'SELECT `id` FROM `video` WHERE `word_id` REGEXP '(^|,)'.$ids.'(,|$)'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.