Reemplace toda la cadena con estrellas

I need a solution to replace whole string with stars in PHP, for example there are strings like:




And depends on string length, it will replace string with the stars like:

test has 4 characters in length so it will be replaced with 4 stars ****.

test123 has 7 characters in length so it will be replaced with 7 stars *******. Y así...

Is there any good solution for that?

preguntado el 03 de mayo de 12 a las 20:05

I really hope you are not utilizing simple masking to hide sensitive data (such as passwords). This method is extremely unsecured. -

@PenguinCoder Well, I'm using it to hide some special codes. But may I know why are you calling this method extremely unsecured? -

It would mean your methods of storing sensitive data are insecure, not particularly the masking itself. IE, if you're storing passwords (or other sensitive data) in plaintext anywhere, then its just a matter of time before someone gets their hands on your 'secured' data. -

Well, its not really sensitive data, as its only a safebox code password in the game, but user will have to login on his account in order to see that stars password. So I guess its okay? -

So I guess its okay? - What constitutes acceptable risk is completely up to you (or your supervisor if such is a work project) to determine. My comment was to bring attention to the method, and perhaps help you think of a better or more secure solution if my statement was indeed the case. -

1 Respuestas

$string = str_repeat('*', strlen($string));

Simply make a new string, consisting of all stars, with length equal to the original.

contestado el 03 de mayo de 12 a las 20:05

Wow, fast and nice answer. Thank you for this great solution :). - Ciclón

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.