2
I have the following numbering:
4716501731980995
I need to split it four ways. Part 2/3 should be replaced by ******** How could I do this?
2
I have the following numbering:
4716501731980995
I need to split it four ways. Part 2/3 should be replaced by ******** How could I do this?
8
The simplest option is to use the function substr_replace()
, in that reply has more details.
Another alternative is to use the function str_split()
to break the string into an array with four elements and contain the zero Indice with the function str_repeat()
to generate the asterisks plus the three Indice containing the last part of the card.
$str = '4716501731980995';
$novo = str_split($str, 4);
echo $novo[0]. str_repeat('*', 8). $novo[3];
Exit:
4716********0995
8
Another option would be to use substr_replace()
, since the string is not multibyte will not be a problem. This will not break/split the string, just insert the asterisks into the defined spaces.
$string = '4716501731980995';
echo substr_replace($string, ' **** **** ', 4, 8);
Upshot:
4716 **** **** 0995
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
There are 16 digits, from the fifth to the tenth second should become asterisks? That
– rray
misworded question. and the other parts? 4***** *0995 or 47 ******995 etc. etc....
– user60252
That’s right, Ray, but I think some of you might have less right, which is in the case of Americanexpress
– Sr. André Baill
Leocaracciolo, can edit as you think it best to be more enlightened for others, at the moment what I could think was this.
– Sr. André Baill
vc q have to say the composition of the 4 parts, because the first and fourth were without padão, example, I can have 1 digit in the first part and 4 in the last, or 2 in the first and 3 in the last, 3 in the first and 2 in the last, 4 in the first and 1 in the last
– user60252
No, think to me... "I need to split it four ways. Part 2/3", that means: 16 digits, / 4 = 4 digits per part - that is, the 2 and 3 part contains exact 4 digits, in this case, must be replaced, as the Rray posted.
– Sr. André Baill
No, the question then should be "I need to divide it into 4 parts" EQUAL. Only part 2/3 has 5 asteristicos separated by space followed by 6 asteristicos that contradicts everything ***** ******
– user60252