Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php实现Gravatar-如何将邮件地址连接到$电邮;变量_Php_Drupal_Drupal 7_Gravatar - Fatal编程技术网

使用php实现Gravatar-如何将邮件地址连接到$电邮;变量

使用php实现Gravatar-如何将邮件地址连接到$电邮;变量,php,drupal,drupal-7,gravatar,Php,Drupal,Drupal 7,Gravatar,Gravatar在下一页有其php实现的描述: 我试图用这段代码在Drupal的用户配置文件和用户图片中实现它 我创建了一个预处理函数,可以在user-profile.tpl.php中打印电子邮件地址 function THEMENAME_preprocess_user_profile(&$variables) { $account = $variables['elements']['#account']; foreach (element_children($vari

Gravatar在下一页有其php实现的描述:

我试图用这段代码在Drupal的用户配置文件和用户图片中实现它

我创建了一个预处理函数,可以在user-profile.tpl.php中打印电子邮件地址

function THEMENAME_preprocess_user_profile(&$variables) {
    $account = $variables['elements']['#account'];
    foreach (element_children($variables['elements']) as $key) {
        $variables['user_profile'][$key] = $variables['elements'][$key];
    }
    $variables['user_profile']['mail'] = $account->mail;
    field_attach_preprocess('user', $account, $variables['elements'], $variables);
}
将代码添加到user profile.tpl.php

print render($user_profile['mail']);
这段代码的工作原理是它应该做的——它在用户配置文件中显示邮件地址。现在我需要使用该地址在配置文件和用户图片中创建Gravatar

我曾尝试将Gravatar网站上的教程与此代码连接起来,但没有成功。下面是代码(我已经尝试了至少20种不同的组合):


我做错了什么?在这一行的引号之间放置什么是正确的表达式?

问题是关于基本的PHP语法,
$variables['user\u profile']['mail']
用于对嵌套数组(即数组中的数组)的简单访问。此外,如果
打印呈现($user\u profile['mail'])
显示用户的电子邮件地址,
$user\u profile['mail']
显然是要传递给自定义
get\u gravatar()函数的电子邮件地址

$variables['user_profile']['gravater_url'] = get_gravatar($user_profile['mail']); 

我建议使用,而不是编写自己的实现。

这与这个问题有什么关系?我已经接受了我设法实现的每个答案,即解决了我的问题的答案。
$email = "['user_profile']['mail']";
$variables['user_profile']['gravater_url'] = get_gravatar($user_profile['mail']);