Home » Php » php – Filter the String, delete any character except number greater than 0 and numbers to the right including zeros

php – Filter the String, delete any character except number greater than 0 and numbers to the right including zeros

Posted by: admin February 25, 2020 Leave a comment

Questions:

The string is “WN0000020kg”. It is reading from external libra. In this case i need to filter that sting and take just integer 20.

I want to make it flexible to be able to filter other formats, if i am using another libra. I have been stuck with this problem a little while. My idea is to make loop which will find 1 <= number <= 9 (0 < number < 10) and take every number after that number (including zeros and deleting other strings).

These are some examples and what they should be filtered in. (All have to be integers)

GN0034700kg => 34700

SN0000303kg => 303

WM0100020kg => 100020

WN2300020kg => 2300020

How to&Answers: