3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $newString = "Give cash back at the rate that WF Visa does. 100,000 points = $1,250. Plus they have better point value when it comes to hotels."; $originalString = $newString; $regex = "/[$#]*(\d+(\.|\,|\s)?\d*(\.|\,|\s)?\d*){3,}[%.\)]*/"; preg_match_all($regex, $originalString, $matches); foreach($matches[0] as $match) { if ($match[0] == "$" || $match[0] == "#") { continue; } $stringLength = strlen($match); if ($match[$stringLength - 1] == "%" || $match[$stringLength - 1] == "." || $match[$stringLength - 1] == ")") { continue; } $replacement = ''; for ($i = 0; $i < strlen($match); $i++) { if ($match[$i] == '-' || $match[$i] == '+' || $match[$i] == ' ' || $match[$i] == '.' || $match[$i] == ',' || $match[$i] == '(' || $match[$i] == ')') { $replacement .= $match[$i]; } else { $replacement .= 'X'; } } echo $replacement; $match = preg_quote($match); echo $match; $newString = preg_replace("/" . $match . "/U", $replacement, $newString); } print_r("ORIGINAL STRING: " . $originalString . "\n"); print_r("FILTERED STRING: " . $newString . "\n"); print_r("MATCHES: \n"); print_r($matches);
based on tuumC
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.3.0alpha1
XXX,XXX 100,000 ORIGINAL STRING: Give cash back at the rate that WF Visa does. 100,000 points = $1,250. Plus they have better point value when it comes to hotels. FILTERED STRING: Give cash back at the rate that WF Visa does. XXX,XXX points = $1,250. Plus they have better point value when it comes to hotels. MATCHES: Array ( [0] => Array ( [0] => 100,000 [1] => $1,250. ) [1] => Array ( [0] => 0 [1] => 0. ) [2] => Array ( [0] => [1] => . ) [3] => Array ( [0] => [1] => ) )