SyntaxFix
Write A Post
Hire A Developer
Questions
Tags
What is the best way for me to do this? Should I use regex or is there another in-built PHP function I can use?
For example, I'd want: 12 months to become 12. Every 6 months to become 6, 1M to become 1, etc.
12 months
12
Every 6 months
6
1M
1
Thank you
This question is related to php string
php
string
Use \D to match non-digit characters.
\D
preg_replace('~\D~', '', $str);
Source: Stackoverflow.com