我已经做了一些研究。我发现你可以序列化然后反序列化得到一个字符串......但我想要一个更好的解决方案。对象到字符串。怎么样?
我收到了IMAP pear模块返回的对象数组(function imap_getmailboxes
)。
public function GetMailBoxes(){
$List = imap_getmailboxes($this->Link, '{'.$this->Server.':'.$this->Port.'}', '*');
$Data = array();
if(is_array($List)){
foreach($List as $Key => $Value){
$Value = unserialize(serialize($Value));
$In = strpos($Value->name, '{');
$Out = strpos($Value->name, '}');
$Part = substr($Value, $Out);
$Value->real_name = explode($Value->delimiter, imap_utf7_decode($Part));
$Value->real_name = (isset($Value->real_name[1]) ? $Value->real_name[1] : null);
$Data[$Key] = $Value;
}
}
return $Data;
}
这里的问题是条码告诉我这个Warning: substr() expects parameter 1 to be string, object given in /home/david/domains/davidbelanger.net/public_html/panel/drivers/mail.php on line 178
。
如何将对象转换为字符串?任何想法,从来没有这样做过。
谢谢。
你为什么这样做'$价值= unserialize(serialize($ Value));'?该行完全无用,请将其删除。 – 2012-04-09 20:14:35
@火箭请读我的第一行。这就是为什么它在第一位。 – 2012-04-09 20:19:52