Why prints the entire line, if I indicated that only the first pocket is needed, with any numbers, before the first one is not?
echo preg_replace('/(\d+)/', '$1', '44f6&sor5t'); should bring 44
Why prints the entire line, if I indicated that only the first pocket is needed, with any numbers, before the first one is not?
echo preg_replace('/(\d+)/', '$1', '44f6&sor5t'); should bring 44
preg_raplace () replaces only those parts of the string that fall under the search expression. All characters that do not fall under the expression - remain unchanged.
echo preg_replace('/(\d+).*/', '$1', '44f6&sor5t'); will result in 44 . Part .* Means 0 or more of any characters, as a result, the expression can be read as "Replace the numbers (what is in the first brackets) and any characters following them with numbers ."
Source: https://ru.stackoverflow.com/questions/770899/
All Articles