Does anyone know what the preg_replace would be for a string to only allow whole numbers and commas? I want to strip all whitespace, letters, symbols, etc, so all that is le
This should do what you need:
$str = preg_replace( array( '/[^\d,]/', // Matches anything that's not a comma or number. '/(?<=,),+/', // Matches consecutive commas. '/^,+/', // Matches leading commas. '/,+$/' // Matches trailing commas. ), '', // Remove all matched substrings. $str );