How to extract Numbers From a String in PHP ?
The purpose of this article is to extract numbers from a string using PHP.
We can use the preg_replace() function for the extraction of numbers from the string.
- /[^0-9]/ pattern is used for finding number as integer in the string (Refer to Example 1)
- /[^0-9\.]/ pattern is used for finding number as double in the string (Refer to Example 2)
Example 2: The complete code for extracting number from the string is as follows
900000000098 90000000.0098 1014
My Personal Notes arrow_drop_up
Please Login to comment...