How can I modify this existing preg_replace to only allow numbers?
function __cleanData($c)
{
return preg_replace("/[^A-Za-z0-9]/", "",$c);
}
This question is related to
php
preg-replace
This should do what you want:
preg_replace("/[^0-9]/", "",$c);
You could also use T-Regx library:
pattern('\D')->remove($c)
T-Regx also:
false
, null
or warnings)Try this:
return preg_replace("/[^0-9]/", "",$c);
Source: Stackoverflow.com