<?php
$newString = "One of the best card on the world I love it and use it everyday for everything, I feel I have $1 000 000 in my pocket All the best Amex of the world, and many thanks Sami Suhail NYC Rock Inc.";
$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);
preferences:
30.87 ms | 402 KiB | 5 Q