{"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<p class=\"wp-block-paragraph\">\u4f7f\u7528 PHP \u5b9e\u73b0 Cravatar \u975e\u5e38\u7b80\u5355\u3002PHP\u63d0\u4f9b\u4e86<code>strtolower()<\/code>\u3001<code>md5()<\/code>\u3001 \u548c<code>urlencode()<\/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<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">$email = \"someone@somewhere.com\";\n$default = \"https:\/\/www.somewhere.com\/homestar.jpg\";\n$size = 40;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b php \u4ee3\u7801\u6784\u5efa\u60a8\u7684\u5934\u50cf url\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">$crav_url = \"https:\/\/cn.cravatar.com\/avatar\/\" . md5( strtolower( trim( $email ) ) ) . \"?d=\" . urlencode( $default ) . \"&amp;s=\" . $size;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efa\u5934\u50cf URL \u540e\uff0c\u60a8\u53ef\u4ee5\u968f\u65f6\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">&lt;img src=\"&lt;?php echo $crav_url; ?>\" alt=\"\" \/><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"<?php echo $grav_url; ?&gt;\" alt=\"\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example\">\u5b9e\u65bd\u793a\u4f8b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\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<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/**\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:\/\/cn.cravatar.com\/avatar\/';\n    $url .= md5( strtolower( trim( $email ) ) );\n    $url .= \"?s=$s&amp;d=$d&amp;r=$r\";\n    if ( $img ) {\n        $url = '&lt;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":"<p>\u4f7f\u7528 PHP \u5b9e\u73b0 Cravatar \u975e\u5e38\u7b80\u5355\u3002PHP\u63d0\u4f9b\u4e86strtolower()\u3001md5()\u3001 \u548curlencode()\u51fd\u6570\uff0c &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"PHP \u56fe\u50cf\u8bf7\u6c42\" class=\"read-more button\" href=\"https:\/\/cravatar.com\/developer\/php-image-requests#more-27263\" aria-label=\"\u66f4\u591a PHP \u56fe\u50cf\u8bf7\u6c42\">\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":{"slim_seo":{"title":"PHP \u56fe\u50cf\u8bf7\u6c42 - Cravatar \u5f00\u53d1\u6587\u6863","description":"\u4f7f\u7528 PHP \u5b9e\u73b0 Cravatar \u975e\u5e38\u7b80\u5355\u3002PHP\u63d0\u4f9b\u4e86 strtolower() \u3001 md5() \u3001 \u548c urlencode() \u51fd\u6570\uff0c\u8ba9\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u5934\u50cfURL\u3002\u5047\u8bbe\u4ee5\u4e0b\u6570\u636e\uff1a \u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b php \u4ee3\u7801\u6784\u5efa\u60a8\u7684\u5934\u50cf url\uff1a \u521b\u5efa\u5934\u50cf URL \u540e\uff0c\u60a8\u53ef\u4ee5\u968f\u65f6\u8f93\u51fa\uff1a \u5b9e\u65bd\u793a\u4f8b \u6b64\u529f\u80fd\u5c06\u5141\u8bb8\u60a8\u4f7f\u7528 PHP \u5feb"},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"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}]}}