jquery - How to replace string with cross after 2 characters of a string in php?
Get the solution ↓↓↓Solution:
You could use this function:
function obfuscate($data) {
// for email addresses: do not obfuscate beyond at symbol
$clear = strpos($data, "@");
// for non-emails addresses: keep last two characters clear
if ($clear === false) $clear = max(0, strlen($data)-2);
// start hiding from 3rd character onwards, or earlier in some exceptional cases:
$hide = max(0, min($clear-1, 3));
return substr($data, 0, $hide) .
str_repeat("x", $clear - $hide) .
substr($data, $clear);
}
echo obfuscate("[email protected]"); // [email protected]
echo obfuscate("9000000001"); // 900xxxxx01
There are some safeguards (using min and max functions) in the code for not producing bad results in extreme cases, like when the email is very short "[email protected]" or the number only has 3 digits.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: gd library extension not available with this php installation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.