PHP MySQL操纵结果?

时间:2013-07-26 01:19:30

标签: php mysql pdo

<?php
include_once('db.php');
session_start();

    $selectEmail = $db->prepare("SELECT `email` FROM `users` WHERE `uid` = :uid");

        $selectEmail->execute(array(':uid' => $_SESSION['uid']));

            $EmailRow = $selectEmail->fetch();  

                $UserEmail = $EmailRow['email'];

                    echo $UserEmail;

?>

我还没有编写任何代码,也没有要求编写任何代码。

这更像是“我该怎么做”这个问题。

无论如何,我的问题是:我如何操纵MySQL的结果?

例如:我从数据库w / PDO中选择一个用户的电子邮件地址,并将其输出到文本输入,以便他们看到他们的电子邮件,但用星号替换它的前三个字符,这样当他们试图改变它我可以验证他们知道真正的电子邮件地址,防止帐户被盗。

我想操作jmc@inbox.com之类的东西到** c@inbox.com。

这是可能的,如果可以的话,我该怎么做?

2 个答案:

答案 0 :(得分:0)

I want to manipulate something like jmc@inbox.com to **c@inbox.com.

您可以尝试使用此功能substr_replace function

答案 1 :(得分:0)

你可以尝试这样的事情。我在代码中使用了适当的注释。

 $userEmail = "info@example.com";
 $len = strlen($userEmail); //Get the length of the email

 list($email, $domain) = explode('@', $userEmail); //Separate domain and mail

 $emailLength = strlen($email); //find mail length
 $maskLength = floor( $emailLength/2 ); //find the length of mask, half of the email length in this example
 $email = substr($userEmail, $maskLength, $len); //remove the characters that needs to be masked

 for($i = 0; $i < $maskLength; $i++){
    $mask .= '*';
 }

 $maskedEmail = $mask . $email;

 echo $maskedEmail; //your output