erok Posted April 12, 2013 Share Posted April 12, 2013 Hi everyone, I have this statement , $phone = ($_POST['phone']);$phone = trim($phone, "\" \""); // Strip off white spaces $phone = mysql_real_escape_string($phone);$phone = addslashes($phone); when user enter phone number into phone field such as;954 333 or 954333I want database register phone number to tablelike 954333 without white space, even if the user type in 954 333.I tried trim or regexp. They did not work out.What function i should use to strip off automatically any white space in the middle.Any help appreciatedErok Link to comment Share on other sites More sharing options...
justsomeguy Posted April 12, 2013 Share Posted April 12, 2013 Use str_replace to replace a space with an empty string. Trim only removes whitespace at the front and end of a string, not the middle. Link to comment Share on other sites More sharing options...
erok Posted April 12, 2013 Author Share Posted April 12, 2013 Hi justsomeguy,I tried these codes below they did not make difference.They did not strip off white space$phone = ($_POST['phone']);$phone = str_replace("\" \"", "\"empty()\"", $phone); // Strip off white spaces $phone = mysql_real_escape_string($phone);$phone = addslashes($phone);and$phone = ($_POST['phone']);$phone = str_replace("\" \"", "\"\"", $phone); // Strip off white spaces $phone = mysql_real_escape_string($phone);$phone = addslashes($phone); Link to comment Share on other sites More sharing options...
erok Posted April 12, 2013 Author Share Posted April 12, 2013 Sorry I tried this one also.It did not work.$phone = ($_POST['phone']);$phone = str_replace("\" \"", "empty()", $phone); // Strip off white spaces $phone = mysql_real_escape_string($phone);$phone = addslashes($phone);with these codes program running fine.Just not stripping off white space. Link to comment Share on other sites More sharing options...
erok Posted April 12, 2013 Author Share Posted April 12, 2013 Thanks for help.This code running properly. It strips off white space. $phone = ($_POST['phone']);$phone = str_replace(" ", "", $phone); // Strip off white spaces $phone = mysql_real_escape_string($phone);$phone = addslashes($phone);Erok Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now