Answer the question
In order to leave comments, you need to log in
How to process text in php?
Hello, tell me how to make the text change well and check.
What do I need?
I pass numbers for example 123412,5123513,312341
I need them to become '123412','5123513','312341' after they are saved
Well, how to make a check that there are only numbers and a comma, but letters are spaces and so on what is not needed just disappeared.
Answer the question
In order to leave comments, you need to log in
Your best bet is to use a regular expression (\d+)
.
$matches = [];
preg_match_all('/(\d+)/', '56, 38, 39', $matches);
$matches
all the numbers found in the string. And from the array they can be displayed separated by commas, using, for example, foreach
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question