Cenzurare o parte dintr-un cuvant
-
- Mesaje: 117
Cenzurare o parte dintr-un cuvant
Salut, cum pot cenzura o parte dintr-un cuvant ? EX: marplo , sa se transforme in m***lo
MarPlo
Mesaje: 4343
Salut
Incearca functia din acest exemplu:
Incearca functia din acest exemplu:
Cod: Selectaţi tot
// Replace in $str the characters starting from $first (0 first character) to $last, with $rep
function repStr($str, $first=0, $last=0, $rep='*'){
$begin = substr($str,0,$first);
$middle = str_repeat($rep,strlen(substr($str,$first,$last)));
$end = substr($str,$last);
$stars = $begin.$middle.$end;
return $stars;
}
$str ='marplo';
//replace in $str the characters from index 1 till the last two characters
$str2 = repStr($str, 1, -2);
echo $str2; // m***lo
Stefan
Mesaje: 117
Mersi mult. Am o lista cu id, nume, parola etc si vreau ca parola sa fie inlocuita cum am zis mai sus. Cum modific acel cod ?
imgur.com/mR0I7U7
Am avut codul
Si am incercat cu
Dar imi da eroare:
imgur.com/i9ecQ6u
imgur.com/mR0I7U7
Am avut codul
Cod: Selectaţi tot
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['nume']; ?></td>
<td><?php echo $row['pass']; ?></td>
Cod: Selectaţi tot
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['nume']; ?></td>
<td>
<?php
function repStr($str, $first=0, $last=0, $rep='//'){
$begin = substr($str,0,$first);
$middle = str_repeat($rep,strlen(substr($str,$first,$last)));
$end = substr($str,$last);
$stars = $begin.$middle.$end;
return $stars;
}
$str = $row['pass'];
//replace in $str the characters from index 1 till the last two characters
$str2 = repStr($str, 1, -2);
echo $str2;
?>
</td>
imgur.com/i9ecQ6u
MarPlo
Mesaje: 4343
Adauga functia repStr() undeva la inceputul fisierului php, inainte de acel cod, sa nu fie in vreo instructiune for() sau while().
Si aplici asa:
Si aplici asa:
Cod: Selectaţi tot
<td><?php echo repStr($row['pass'], 1, -2); ?></td>
Stefan
Mesaje: 117
Iti multumesc foarte mult <3