How can I Replace letters with asterisks except first and last character
for example: house -> h***e Database
<div id="ld">
<?php
$base=mysqli_connect('localhost','root','','exercise');
$request="select text from exercise";
/*
Here I want to show all words from database but with letters replaced
with asterisks (expect first and last letter)
*/
mysqli_close($base)
?>
</div>
EDITED CODE:
<div id="ld">
<?php
$base=mysqli_connect('localhost','root','','exercise');
$request="select text from exercise";
$str=mysqli_query($base, $request);
function get_starred($str) {
$len = strlen($str);
return substr($str, 0, 1).str_repeat('*', $len - 2).substr($str, $len - 1, 1);
}
$myStr = $str;
echo get_starred($myStr);
mysqli_close($base)
?>
</div>
and error: Fatal error: Uncaught TypeError: strlen(): Argument #1 ($str) must be of type string, mysqli_result given on Line 7
>Solution :
There is a way to do it in mysql. Other answers may give PHP solution, but in mysql:
SELECT CONCAT(LEFT(text,1), REPEAT('*',LENGTH(text)-2), RIGHT(text,1)) AS text FROM exercise
simply concatenate the first letter, then your asterisks, then last letter.