Germaris Posted August 27, 2007 Share Posted August 27, 2007 Hi there! I've built a search that works but relies on the users to input their request very accurately. The data they're searching on are phone numbers which come from a MySQL DB. In the DB, phone numbers (from all over the world) are stored WITH spaces, like for example: 123 456 7890 What happens is people are typing in "1234567890" and this is coming up with no result. This also occurs if users type in: "123 4567890"... May be it would be also necessary to eliminate all spaces in the user's request prior to execute the query... How should I write my queries to make them work? Due to the infinite power of PHP, I'm quite sure a simple solution exists. The script could first transform the user's string in a string with no spaces then compares this new string against those contained in the DB ignoring while reading the existing spaces... This method avoid modification of the DB... Any help would be most appreciated and I thank you in advance for it. Quote Link to comment https://forums.phpfreaks.com/topic/66866-ignoring-spaces/ Share on other sites More sharing options...
wildteen88 Posted August 27, 2007 Share Posted August 27, 2007 To remove spaces use a simple string replacement with str_replace, eg: $searchText = "123 4567 890"; $newSearchText = str_replace(' ', '', $searchText); echo $newSearchText; Quote Link to comment https://forums.phpfreaks.com/topic/66866-ignoring-spaces/#findComment-335177 Share on other sites More sharing options...
Germaris Posted August 27, 2007 Author Share Posted August 27, 2007 Thank you very much for your appreciated reply! Okay, understood, this is the first step: conversion of the user's string. Now, how can I write my MySQL query to make it reading the field ignoring the spaces it contains? Because if I don't do that, it will returns no result... Quote Link to comment https://forums.phpfreaks.com/topic/66866-ignoring-spaces/#findComment-335182 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.