2011-01-14 36 views
1

我現在有一些關於隱藏某些字符的問題...我想隱藏帳戶管理中用戶名前面的幾個字符。這裏是我的問題: 在帳戶管理我有$用戶名在表中是從數據庫中取出我需要這個用戶名不會像這樣顯示: 用戶名=> ** rname - 只需用「」替換幾個第一個字符使用PHP或類似的代碼的網頁。如何隱藏從數據庫打印的文本

回答

3

我假設你不想讓他們知道用戶名中有多少個字符?使用substr_replace()

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

輸出:**rname

當然,如果一個用戶名較短這是不行的。你可以做

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

我不太確定你在說什麼。你想達到這個目的嗎?

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

,你可以使用類似這樣

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

?> 
+0

那是什麼? :-) – Byakugan 2011-01-14 01:25:04

+0

這是你的問題的答案。你嘗試過嗎? – andrewk 2011-01-14 01:30:34

0

你可以這樣做;

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

從字符串中刪除前兩個字符。