如何从该数组中获取电子邮件?
array(16) {
[0]=> string(273) ""guid":"","contactId":"44","contactName":"_, atri","email":"atri_megrez@yahoo.com","emaillink":"http:\/\/mrd.mail.yahoo.com\/compose?To=atri_megrez%40yahoo.com","isConnection":false,"connection":"","displayImg":null,"msgrID":"atri_megrez","msgrStatus":"","isMsgrBuddy":122},"
[1]=> string(260) ""guid":"","contactId":"100","contactName":"afrin","email":"fida_cuty123@yahoo.com","emaillink":"http:\/\/mrd.mail.yahoo.com\/compose?To=fida_cuty123%40yahoo.com","isConnection":false,"connection":"","displayImg":null,"msgrID":"","msgrStatus":"","isMsgrBuddy":false},"
[2]=> string(258) ""guid":"","contactId":"101","contactName":"afrin","email":"waliyani@yahoo.com","emaillink":"http:\/\/mrd.mail.yahoo.com\/compose?To=waliyani%40yahoo.com","isConnection":false,"connection":"","displayImg":null,"msgrID":"","msgrStatus":"","isMsgrBuddy":false},"
}发布于 2011-02-22 15:20:57
看起来该数组中的每个字符串都是JSON数据。
如果您使用的是现代版本的PHP,那么可以使用json_decode()将数据转换为可用的格式。
foreach($array as $string) {
$json = json_decode($string);
echo "Email = {$json->email}\n";
}发布于 2011-02-22 15:17:43
如果你可以发布一个数据示例(例如:数据来自何处,数组的print_r()输出的一个格式正确的示例),这将会有所帮助,但从我收集的信息来看,这将从数组中获得电子邮件:
/* Make $array hold the given array */
$emails = array();
foreach($array as $contact){
$emails[] = $contact['email'];
}
// All emails
print_r($emails);发布于 2011-02-22 15:19:33
您可以在每个数组元素上运行regexp。类似于:/“电子邮件”:“(.+?)”/
$emails = array();
foreach ($array as $str)
{
if (preg_match('/"email":"(.+?)"/', $str, $matches))
{
$emails[] = $matches[1];
}
}https://stackoverflow.com/questions/5075162
复制相似问题