开发者

How to hide text printed from DB

I have now some question about hiding some characters ... I want to hide first few characters fro user name on account management. Here is my problem: On account management I have $username in tabl开发者_JAVA技巧e which is taken from DB an I need this username not to be displayed like this: Username => **rname - just replace few first characters with "" using php or similar code for webpages.


I assume you don't want to let them know how many characters are in the username, either? Use substr_replace()

$val = 'username';
$output = substr_replace($val, '**', 0, -5);

Outputs: **rname

Of course if a username is shorter this won't work. You could instead do

$output = substr_replace($val, '**', 0, 3); // or some other length value


echo '***' . substr($username, 3);


I'm not really sure what you are trying to say. Do you want to achieve this?

echo '***', substr($username, 3);


You could do;

print '***'.substr($username, 3);


substr($username, 2);

remove first two chars from the string.


you could use something like this

<?php
$username = theusernamehere;
$userhide = str_pad(substr($username, -4), strlen($username), 'x', STR_PAD_LEFT);
$userhide = str_replace('xxxx','xx',$userhide);
echo $userhide;

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜