treeleaf20 Posted August 24, 2011 Share Posted August 24, 2011 All, I have a zip code and for example the zip code is 01101. How can I determine if the first character in this is a zero? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/245608-determine-if-the-first-character-is-a-0/ Share on other sites More sharing options...
requinix Posted August 24, 2011 Share Posted August 24, 2011 Try using substr. Quote Link to comment https://forums.phpfreaks.com/topic/245608-determine-if-the-first-character-is-a-0/#findComment-1261483 Share on other sites More sharing options...
Maq Posted August 24, 2011 Share Posted August 24, 2011 All, I have a zip code and for example the zip code is 01101. How can I determine if the first character in this is a zero? Thanks in advance. There are a multitude of ways to do this. Another way: $zip = "01101"; echo $zip[0]; Quote Link to comment https://forums.phpfreaks.com/topic/245608-determine-if-the-first-character-is-a-0/#findComment-1261487 Share on other sites More sharing options...
AbraCadaver Posted August 24, 2011 Share Posted August 24, 2011 if(strpos($zip, '0') === 0) { //yes } Quote Link to comment https://forums.phpfreaks.com/topic/245608-determine-if-the-first-character-is-a-0/#findComment-1261490 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.