R
R
rusgayfer2018-03-04 17:48:17
PHP
rusgayfer, 2018-03-04 17:48:17

How to replace characters with an asterisk in a string?

There is a code:

5959067ca46f67b671340d6472fe046662fb8nc5cd338f0e449563b93a330f3ca6fe2d7m812875b473fae

You need to cut it to get this look: How to do it?
5959********3fae

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Sdk, 2018-03-04
@rusgayfer

as an option

$str = '5959067ca46f67b671340d6472fe046662fb8nc5cd338f0e449563b93a330f3ca6fe2d7m812875b473fae';
$new_str = mb_substr($str, 4) . '********' . mb_substr($str, -4);

upd:
$new_str = substr($str, 0, 4) . '********' . substr($str, -4);

A
Anton, 2018-03-04
@sHinE

Cut out the first 4, add the required number of stars, cut out the last 3.
Cut with substr()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question