php get number from string 1

php get number from string

phpCopy 

Here is what the above code is Doing:
1. The preg_replace() function searches a string for a pattern, and replaces the pattern with a specified replacement.
2. The pattern we’re searching for is [^0-9]. This pattern means “any character that is not a digit”.
3. The replacement is an empty string. This means that the pattern will be replaced with nothing, effectively deleting it.
4. The string we’re searching is $string.
5. The result is stored in $outputString.

Similar Posts