{"id":27263,"date":"2023-08-15T11:00:18","date_gmt":"2023-08-15T03:00:18","guid":{"rendered":"https:\/\/cravatar.com\/developer\/?p=27263"},"modified":"2023-08-15T11:01:57","modified_gmt":"2023-08-15T03:01:57","slug":"php-image-requests","status":"publish","type":"post","link":"https:\/\/cravatar.com\/developer\/php-image-requests","title":{"rendered":"PHP \u56fe\u50cf\u8bf7\u6c42"},"content":{"rendered":"\n

\u4f7f\u7528 PHP \u5b9e\u73b0 Cravatar \u975e\u5e38\u7b80\u5355\u3002PHP\u63d0\u4f9b\u4e86strtolower()<\/code>\u3001md5()<\/code>\u3001 \u548curlencode()<\/code>\u51fd\u6570\uff0c\u8ba9\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u5934\u50cfURL\u3002\u5047\u8bbe\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n\n\n\n

$email = "someone@somewhere.com";\n$default = "https:\/\/www.somewhere.com\/homestar.jpg";\n$size = 40;<\/code><\/pre>\n\n\n\n

\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b php \u4ee3\u7801\u6784\u5efa\u60a8\u7684\u5934\u50cf url\uff1a<\/p>\n\n\n\n

$crav_url = "https:\/\/cravatar.cn\/avatar\/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;<\/code><\/pre>\n\n\n\n

\u521b\u5efa\u5934\u50cf URL \u540e\uff0c\u60a8\u53ef\u4ee5\u968f\u65f6\u8f93\u51fa\uff1a<\/p>\n\n\n\n

<img src="<?php echo $crav_url; ?>" alt="" \/><\/code><\/pre>\n\n\n\n

\"\"<\/p>\n\n\n\n

\u5b9e\u65bd\u793a\u4f8b<\/h3>\n\n\n\n

\u6b64\u529f\u80fd\u5c06\u5141\u8bb8\u60a8\u4f7f\u7528 PHP \u5feb\u901f\u8f7b\u677e\u5730\u5c06 Cravatar \u63d2\u5165\u9875\u9762\u4e2d\uff1a<\/p>\n\n\n\n

\/**\n * Get either a Cravatar URL or complete image tag for a specified email address.\n *\n * @param string $email The email address\n * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]\n * @param string $d Default imageset to use [ 404 | mp | identicon | monsterid | wavatar ]\n * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]\n * @param boole $img True to return a complete IMG tag False for just the URL\n * @param array $atts Optional, additional key\/value attributes to include in the IMG tag\n * @return String containing either just a URL or a complete image tag\n * @source https:\/\/cravatar.com\/developer\/php-image-requests\n *\/\nfunction get_cravatar( $email, $s = 80, $d = 'mp', $r = 'g', $img = false, $atts = array() ) {\n    $url = 'https:\/\/cravatar.cn\/avatar\/';\n    $url .= md5( strtolower( trim( $email ) ) );\n    $url .= "?s=$s&d=$d&r=$r";\n    if ( $img ) {\n        $url = '<img src="' . $url . '"';\n        foreach ( $atts as $key => $val )\n            $url .= ' ' . $key . '="' . $val . '"';\n        $url .= ' \/>';\n    }\n    return $url;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

\u4f7f\u7528 PHP \u5b9e\u73b0 Cravatar \u975e\u5e38\u7b80\u5355\u3002PHP\u63d0\u4f9b\u4e86strtolower()\u3001md5()\u3001 \u548curlencode()\u51fd\u6570\uff0c ... <\/p>\n

\u7ee7\u7eed\u9605\u8bfb<\/a><\/p>\n","protected":false},"author":18727,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[22],"class_list":["post-27263","post","type-post","status-publish","format-standard","hentry","category-software","tag-php","no-featured-image-padding"],"_links":{"self":[{"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/posts\/27263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/users\/18727"}],"replies":[{"embeddable":true,"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/comments?post=27263"}],"version-history":[{"count":0,"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/posts\/27263\/revisions"}],"wp:attachment":[{"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/media?parent=27263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/categories?post=27263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cravatar.com\/developer\/wp-json\/wp\/v2\/tags?post=27263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}