realjumper Posted February 23, 2007 Share Posted February 23, 2007 Hi, The student id that is entered into a form is always a string of numbers....and no student numbers ever start with zero ('0'). Yet, some student has entered a zero before his student number...sigh! So, how can I detect whether the first interger in the string is a '0', and if it is, strip it out? I'm searching for the answer as we speak, but you may have an idea. Many thanks, Neil Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 23, 2007 Share Posted February 23, 2007 <?php $studentID = "0002345607"; $result = preg_replace('/^0+/', "", $studentID); echo $result; //2345607 ?> Try this. Make sure that the ID is a string, otherwise it will output some funny answers. Quote Link to comment Share on other sites More sharing options...
realjumper Posted February 23, 2007 Author Share Posted February 23, 2007 Oh that's perfect....thank you :-) Quote Link to comment Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 $studentID = round($studentID); So do you work for a school in New Zealand? I work for a school district and I used to work for a NZ based company? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 intval() might work too, if the ID number is only numbers. Quote Link to comment 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.