The people who have a regular expression test for any letter in any language?
- It is not entirely clear, you need to catch a certain letter, or vice versa, you need to catch everything except letters. - vdk company
- I pull out $ _SERVER ['REQUEST_URI'] and get / id + number, and I’m not allowed to check anything after that number is not a sign or letter - avpah
|
1 answer
(int) $ id; - even if after the first number there are any characters and numbers, they are “cut off”
$id = '15-W_T_F?+100500'; echo (int)$id; // результат - 15 //но $id = 'W_T_F?+100500'; echo (int)$id; // результат - 0
You can of course and regular season, but if there is an option to do without it, then do not use.
echo preg_replace('/([^\d]+)[^\D]+/i','',$id); // результат - 15
- and how to write if $ id is even a letter ??? - AvpA
- We are looking for everything that is not a number: if (preg_match ('/ [^ \ d] + / i', $ id)) {echo "Besides numbers, there is something else"; } else {echo "Bukaf ek"; } - Deonis
|