简体   繁体   English

PHP:星号仅最后 4 位数字

[英]PHP: Asterisk only last 4 digits of number

Hi i want to change the last 4 digits of number with asterisk For example: 123456789101嗨,我想用星号更改数字的最后 4 位例如:123456789101

I want it to become 12345678**** in database (PHPMyAdmin)我希望它成为数据库中的 12345678**** (PHPMyAdmin)

This is my code这是我的代码

 if(isset($_POST['add'])){
        
    $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
        
    $voter = $_POST['voters_id']; (**I want the voters_id to be asterisk only last 4 digits**)
    }
        
    
 $sql = "INSERT INTO voters (voters_id, password) VALUES ('$voter', '$password')";
            
    if($conn->query($sql)){
                
    echo '<script language="javascript">';
                
    echo 'alert("Voters sucessfully insert")';
                
    echo '</script>';
                
    echo ("<script>location.href='index.php'</script>");
        
    }
        
    
            
    else{
               
     $_SESSION['error'] = $conn->error;
            
    }
        
    }

Is there any idea on how to solve this problem?关于如何解决这个问题有什么想法吗? Thank you in advance!先感谢您!

Edited it to match what you want;编辑它以匹配你想要的; here ya go:这里是 go:

    $id = "0123456789";

    $eid = function() use ($id){
        $half1 = substr($id, 0, strlen($id) -  4);
        return $half1."****";
    };

Input:输入:

0123456789

Output Output

012345****

Live Demo: http://sandbox.onlinephpfunctions.com/code/3ad1e3e028e696b1e8befe5e9a971ba468ba4d9e现场演示: http://sandbox.onlinephpfunctions.com/code/3ad1e3e028e696b1e8befe5e9a971ba468ba4d9e

I just don't understand how you're going to get the original numbers back from the asterisks but to each is their own lol.我只是不明白你将如何从星号中获取原始数字,但每个人都是他们自己的哈哈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM