Is there a way to generate a 5 digit zip code/postcode using fzaninotto's Faker?
His provided function to do so, $faker->postcode
, does not offer parameters to limit its size, so it often gives a 9-digit postcode instead of 5, e.g., 10278-4159 instead of 10278. This is problematic for seeding a database, because my sql database has a zipcode column of INT(5).
I know I can resort to just generating a random 5 digit number with Faker, but I wanted to know if there was a native way of generative 5 digit zip codes.
substr()
->$postcode = (strlen($faker->postcode) > 5) ? substr($faker->postcode,0,5) : $faker->postcode;
– Contractile0
so this would cause an issue. Demo of leading0
issue; sqlfiddle.com/#!9/814ba/1... Couldn't you just take the first 5 characters? – Determinate02108
into2108
and have to left-pad it for display. Zip codes are not integers. – Sext