How to display phone number in yii2 so that only the last 4 digits are displayed?

  • 0
    Hello, I have a gridview table, how to display phone numbers from db so that the last 4 digits are displayed in the client side .. Or should this be done with js?
    It needs to be displayed like this:
    +7 (123) *** - 34-56
    That is, make the first 3 digits as asterisks
    JavaScript Arabella Patrick, Aug 29, 2019

  • 1 Answers
  • 0
    The easiest way, put it in php

    $tel = '+7(918)483-50-50';
    $tel_array = str_split($tel);
    $tel_array[7] = $tel_array[8] = $tel_array[9] = '*';
    $new_tel = implode($tel_array);




    at the entrance you have a phone number in this format +7 (918) 483-50-50 '

    at the exit you will receive +7 (918) *** - 50-50
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!