我有一個包含以下字符串的會話變量。php從字符串中提取值
a:2:{s:7:"LoginId";s:32:"361aaeebef992bd8b57cbf390dcb3e8d";s:8:"Username";s:6:"aaaaaa";}
我想提取用戶名「aaaaaa」的值。任何人都可以建議更簡單/更有效的方式
$session_data = unserialize($_SESSION["SecurityAccess_CustomerAccess"]);
$session_user_array = explode(';', $_SESSION["SecurityAccess_CustomerAccess"]);
$temp = $session_user_array[3];
$temp = explode(':', $temp);
$username = $temp[2];
echo $username;
它只是得到了醜陋......不得不去掉引號。
if ($_SESSION["SecurityAccess_CustomerAccess"]){
$session_data = unserialize($_SESSION["SecurityAccess_CustomerAccess"]);
$session_user_array = explode(';', $_SESSION["SecurityAccess_CustomerAccess"]);
$temp = $session_user_array[3];
$temp = explode(':', $temp);
$temp = str_replace("\"", "", $temp[2]);
$username = $temp;
echo $username ;
}
fuc&ing brilliant!必須閱讀字符串和數組的800頁! – 2010-07-14 22:35:55