I need correct strings can someone tell me if this is right for phone number and zip, i dont need anything fancy i just want however many numbers from 0-9 to be strored for both of them. This is what i have so far; $property_zip = nl2br($_POST['property_zip']); $property_phone = ereg_replace("[^0-9]", "", $_POST['property_phone']); can i do something like this? $property_zip = substr(0, 9),($_POST['property_zip']); $property_phone = substr(0, 9),($_POST['property_phone']);
nl2br() will convert new line characters (\n) to the HTML equivalent <br />. It doesn't do anything related with numbers. Your ereg_replace() pattern removes anything that isn't a number from a string. Isn't this what you want to do?
Hi Nico, Ok so lets say i do this; $property_zip = ereg_replace("[^0-9]", "", $_POST['property_zip']); $property_phone = ereg_replace("[^0-9]", "", $_POST['property_phone']); But than when i type numbers in property_phone it gives me output of numbers but with commas between them, LOL do i need to set mysql row differently I currently have something like; int(11)
Commas? lol. Hmm try this: $property_phone = preg_replace('/\D/', null, $_POST['property_phone']); PHP: And you don't really need substr(), because MySQL will just cut the sting at offset 10 (offset starts at 0, it's still 11 characters), so it's impossible that the user enters too long numbers. Maybe you should change your field type though, because there are phone numbers with more than 11 digits. (At least if you accept international numbers with county prefix.)
ok i changed it to the line of code you suggested and it outputted all the numbers except for the 0 I typed in : 0840990712 and it gave me output of : 840990712 about the commas i fixed that. I had field set to this; <?=number_format($row['seller_phone']);?> but i changed to this <?=$row['seller_phone'];?>
I think that's a problem with the INT field in the database, and not the code. Try changing it to VARCHAR. The code shouldn't allow any other characters, so it doesn't really matter in the end.
Excellent work, yes you are right it needed to change to VARCHAR, it now works perfect, thanks very much!