Ok, let’s say I have a string that is CSV: 01,02,05,10,11,13.. what would be the easiest way to remove the leading zeros?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
preg_replacefor this:EDIT: Updated the regex to work with numbers with a
0in the middle of them. (i.e. 101)Thanks to @BoltClock for helping fix the regex.
Output:
The advantage to doing it this way is you don’t have to mess with turning all the text into an array, modifying it/looping through it, and then turning it back into text.