How to show half the word normal and hide the other half with *

Viewed 26
$str = "example";
$login = mb_substr($str, 0, 3);
echo "$login";

How to show half the word normal and hide the other half with * like "exa****"

2 Answers

try to insert a command to include *

$str = "example";
$login = substr($str, 0, 3);
for ($i=3;$i<strlen($str);$i++) $login = $login."*";
echo "$login";
$str = "example";
$start = intval(strlen($str)/2); // Find the half of the string position
$login = substr($str, 0, $start); // Cut the rest from $start
for ($i = $start; $i < strlen($str); $i++) $login = $login."*"; // Add * to the rest
echo "$login";

This will work better with other string, not just "example"

Related