Pawn Posted October 20, 2010 Share Posted October 20, 2010 The goal is to interpret user search submissions like the following in an intelligent way. "oscar wilde 1903-1910 £4-10" Ideally after pattern matching such a query the script would have variables like $price_min, $price_max, $year_min, $year_max and $query_clean to work with. With these we could construct really useful SQL. All I've got for my efforts over the last couple of hours has been a headache. Can anyone help? Pseudo-code: $q = $_GET['query'] $price_range_expr = some_regex $year_range_expr = some_more_regex if $price_range = match all $price_range_expr in $q $q = strip $price_range from $q $price_min = $price_range[1] $price_max = $price_range[2] endif if $year_range = match all $year_range_expr in $q $q = strip $year_range from $q $price_min = $year_range[1] $price_max = $year_range[2] endif Link to comment https://forums.phpfreaks.com/topic/216396-parse-query-for-year-and-price-ranges/ Share on other sites More sharing options...
carpiediem Posted October 20, 2010 Share Posted October 20, 2010 Give this a shot. $price_range_expr = '/£(\d+)-£?(\d+)/'; $year_range_expr = '/([12]\d{3})-([12]\d{3})/'; Remember, if the query itself includes a year or price range, you'll run into trouble. Link to comment https://forums.phpfreaks.com/topic/216396-parse-query-for-year-and-price-ranges/#findComment-1124548 Share on other sites More sharing options...
Pawn Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks! Close, but no cigar. There's a test page here if it's any use. Link to comment https://forums.phpfreaks.com/topic/216396-parse-query-for-year-and-price-ranges/#findComment-1124898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.