Jump to content

[SOLVED] hiding part of a string? how-to?


monkeytooth

Recommended Posts

What I am thinking is something to the effect of when you sign up for something and use your credit card it blanks out all but the last 3 or 4 digits.. I know i can do something with str_repeat and strlen.. but breaking it apart to the last 3 or 4 is that part thats getting me. Right now im stuck with all or none.. Im not working with cards just for refrence, and the strings can be 8 to 25 char long so im looking for something that i can make it ****** the first 5 to 22 chars then display the last 3.. any ideas?

Link to comment
https://forums.phpfreaks.com/topic/133516-solved-hiding-part-of-a-string-how-to/
Share on other sites

<?php
$number = 123456789;
$number_length = strlen($number)-5;
$replace = NULL;
for($i=0;$i<=$number_length;$i++){
$replace .= '*';
}
$result = substr_replace($number, $replace, 0, $number_length);
echo $result; //should print *****6789
?>

 

Haven't checked it, but should work

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.