{"id":701,"date":"2023-02-14T11:25:22","date_gmt":"2023-02-14T02:25:22","guid":{"rendered":"https:\/\/blog.mydepot.kr\/?p=701"},"modified":"2023-02-22T17:22:58","modified_gmt":"2023-02-22T08:22:58","slug":"php-ai-chatgpt%eb%a1%9c-%eb%a7%8c%eb%93%a0-%ec%83%9d%ec%9d%bc-%ea%b8%b0%eb%85%90%ec%9d%bc-%ea%b3%84%ec%82%b0-%ed%95%a8%ec%88%98","status":"publish","type":"post","link":"https:\/\/blog.mydepot.kr\/?p=701","title":{"rendered":"[PHP + AI] CHATGPT\ub85c \ub9cc\ub4e0 \uc0dd\uc77c, \uae30\ub150\uc77c \uacc4\uc0b0 \ud568\uc218"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nfunction calculate_anniversaries($birthday, $debut)\n{\n      \/\/ Get current date\n      $now = new DateTime();\n\n      \/\/ Convert birthday to DateTime object\n      $birthday = DateTime::createFromFormat(&#039;md&#039;, $birthday);\n      $birthday-&gt;setDate(intval($now-&gt;format(&#039;Y&#039;)), $birthday-&gt;format(&#039;m&#039;), $birthday-&gt;format(&#039;d&#039;));\n\n      \/\/ Check if birthday has already passed in current year\n      if ($now &gt; $birthday) {\n            $birthday-&gt;modify(&#039;+1 year&#039;);\n      }\n\n      \/\/ Calculate days until next birthday\n      $days_to_next_birthday = ($now-&gt;diff($birthday)-&gt;days) % 365;\n\n      \/\/ Convert debut to DateTime object\n      $debut = new DateTime($debut);\n\n      \/\/ Calculate days since debut\n      $days_since_debut = $now-&gt;diff($debut)-&gt;days;\n\n      \/\/ Calculate the nearest debut anniversary (in days)\n      $nearest_debut_anniversary = ($days_since_debut % 365) ? 365 - ($days_since_debut % 365) : 0;\n\n      \/\/ Calculate the year of the nearest debut anniversary\n      $nearest_debut_anniversary_year = intval($days_since_debut \/ 365) + ($nearest_debut_anniversary === 0 ? 0 : 1);\n\n      \/\/ Calculate the nearest 100-day anniversary (in days)\n      $nearest_100_day_anniversary = ($days_since_debut % 100) ? 100 - ($days_since_debut % 100) : 0;\n\n      \/\/ Calculate the number of the nearest 100-day anniversary\n      $nearest_100_day_anniversary_number = intval($days_since_debut \/ 100) + 1;\n\n      \/\/ Return all the results\n      return &#x5B;\n            &quot;\uc0dd\uc77c D-DAY&quot; =&gt; $days_to_next_birthday,\n            &quot;\ubc29\uc1a1 X\uc77c\uc9f8&quot; =&gt; $days_since_debut + 1,\n            &quot;\uc8fc\ub144 D-DAY&quot; =&gt; $nearest_debut_anniversary,\n            &quot;\uba87\uc8fc\ub144&quot; =&gt; $nearest_debut_anniversary_year,\n            &quot;\uba87\ubc31\uc77c D-DAY&quot; =&gt; $nearest_100_day_anniversary,\n            &quot;\uba87\ubc31\uc77c&quot; =&gt; $nearest_100_day_anniversary_number * 100\n      ];\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\uc704 \ud568\uc218\ub294 \uc544\ub798\uc758 \uba85\ub839\uc73c\ub85c CHATGPT\uc5d0 \ub123\uc740 \ud6c4, \uc77c\ubd80 \uac00\uacf5 \ubc0f \uc218\uc815\ud55c \uacb0\uacfc \uc785\ub2c8\ub2e4.\n\nPHP\ub85c \ud568\uc218\ub97c \ub9cc\ub4e4\uc5b4 \uc918.\n\n1. \uc785\ub825\uac12\uc740 \ub450\uac00\uc9c0\uc57c. \uccab\ubc88\uc9f8\ub294 \uc6d4\uacfc \uc77c\ub85c \uc774\ub8e8\uc5b4\uc9c4 4\uc790\ub9ac \uc22b\uc790\uc758 \uc0dd\uc77c\uc774\uc57c, \uc608\ub97c \ub4e4\uba74 \uc0dd\uc77c\uc774 1\uc6d4 5\uc77c\uc774\uba74 &quot;0105&quot; \ub97c \uc785\ub825\ud560\uac70\uc57c. \uadf8\ub9ac\uace0 \ub450\ubc88\uc9f8\ub294 \ub370\ubdd4\uc77c\uc778\ub370 \ud615\uc2dd\uc740 &quot;2000-01-01 00:00:00&quot; \uc73c\ub85c \uc785\ub825\ud560\uac70\uc57c.\n2. \ucd9c\ub825\uc740 \ub2e4\uc74c \uc0dd\uc77c\uc774 \uc624\ub298\ub85c\ubd80\ud130 \uba70\uce60 \ub0a8\uc558\ub294\uc9c0, \ub370\ubdd4\uc77c\ub85c\ubd80\ud130 \uba70\uce60 \uc9c0\ub0ac\ub294\uc9c0, \uc624\ub298\ub85c\ubd80\ud130 \uc81c\uc77c \uac00\uae4c\uc6b4 \ub370\ubdd4\uc77c X\uc8fc\ub144 \uae30\ub150\uc77c\uc774 \uc624\ub298\ub85c\ubd80\ud130 \uba70\uce60 \ub0a8\uc558\ub294\uc9c0, \uc624\ub298\ub85c\ubd80\ud130 \uc81c\uc77c \uac00\uae4c\uc6b4 \ub370\ubdd4\uc77c X\uc8fc\ub144 \uae30\ub150\uc77c\uc774 \uba87\uc8fc\ub144 \uae30\ub150\uc77c\uc778\uc9c0, \ub370\ubdd4\uc77c\uc5d0\uc11c \uc81c\uc77c \uac00\uae4c\uc6b4 \uba87\ubc31\uc77c \uae30\ub150\uc77c\uc774 \uc624\ub298\ub85c\ubd80\ud130 \uba70\uce60 \ub0a8\uc558\ub294\uc9c0, \uc81c\uc77c \uac00\uae4c\uc6b4 \uba87\ubc31\uc77c \uae30\ub150\uc77c\uc774 \uba87\ubc31\uc77c \uae30\ub150\uc77c\uc778\uc9c0, \ubaa8\ub450 \uacc4\uc0b0\ud574\uc11c \ubc18\ud658\ud574 \uc918.\n3. \ubaa8\ub4e0 \ubc18\ud658\uac12\uc758 \ub2e8\uc704\ub294 \uc77c(day)\ub85c, \uc815\uc218\ub85c \ubcc0\ud658\ud574\uc11c \ubc18\ud658\ud574 \uc918.\n4. \ubaa8\ub4e0 \ubc18\ud658\uac12 \ubc30\uc5f4\uc758 \ud0a4\ub294 \ud55c\uae00\ub85c \ubd80\ud0c1\ud574.\n5. \ub370\ubdd4\uc77c \uae30\ub150\uc77c \uacc4\uc0b0\ud560 \ub54c, \ub370\ubdd4 \ub2f9\uc77c\uc744 1\uc77c\uc9f8\ub85c \uacc4\uc0b0\ud574 \uc918.\n6. \ub2f5\ubcc0\uc740 20\uc904\uc529 \ub098\ub220\uc11c \ub300\ub2f5\ud574 \uc918.\n<\/pre><\/div>\n\n\n<p>\uc704 \ud568\uc218\ub97c \ucd94\uac00 \uac1c\uc120\ud55c \ud568\uc218 \uc785\ub2c8\ub2e4. (20230222)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nfunction calculate_anniversaries($birthday, $debut) {\n      $returnArr = &#x5B;\n            &quot;birth_dDay&quot; =&gt; null, \/\/ \uc0dd\uc77c D-Day\n            &quot;debut_dDay&quot; =&gt; null, \/\/ \ubc29\uc1a1 X\uc77c\uc9f8\n            &quot;anniver_dDay&quot; =&gt; null, \/\/ \uc8fc\ub144 D-Day            \n            &quot;what_year_anniver&quot; =&gt; null, \/\/ \uba87\uc8fc\ub144      \n            &quot;d100_dDay&quot; =&gt; null, \/\/ \uba87\ubc31\uc77c D-Day      \n            &quot;what_d100_day_anniver&quot; =&gt; null, \/\/ \uba87\ubc31\uc77c\n            &quot;anniver_date&quot; =&gt; null \/\/ \uc8fc\ub144 or \uba87\ubc31\uc77c \ub0a0\uc9dc\n      ];\n\n      \/\/ \ud604\uc7ac \uc790\uc815 \uc2dc\uac04\n      $now = new DateTime(&quot;midnight&quot;);\n\n      \/\/ \uc0dd\uc77c \ub514\ub370\uc774 \uacc4\uc0b0\n      if($birthday !== &quot;0000&quot;){\n            \/\/ Convert birthday to DateTime object\n            $birthday = DateTime::createFromFormat(&#039;md&#039;, $birthday);\n            $birthday-&gt;setDate(intval($now-&gt;format(&#039;Y&#039;)), $birthday-&gt;format(&#039;m&#039;), $birthday-&gt;format(&#039;d&#039;));\n\n            \/\/ Check if birthday has already passed in current year\n            if ($now &gt; $birthday) {\n                  $birthday-&gt;modify(&#039;+1 year&#039;);\n            }\n\n            \/\/ Calculate days until next birthday\n            $returnArr&#x5B;&quot;birth_dDay&quot;] = ($now-&gt;diff($birthday)-&gt;days) % 365;\n      }\n\n      \/\/ \ub370\ubdd4 \uc774\ubca4\ud2b8 \uacc4\uc0b0\n      if($debut !== &quot;2000-01-01 00:00:00&quot;){\n            \/\/ Convert debut to DateTime object\n            $debut = new DateTime($debut);\n\n            \/\/ Calculate days since debut\n            \/\/ $days_since_debut = $now-&gt;diff($debut)-&gt;days;\n            $days_since_debut = (int)$debut-&gt;diff($now)-&gt;format(&#039;%r%a&#039;);\n\n            if($days_since_debut &lt; 0){\n                  \/\/ \ub370\ubdd4 \uc804\n                  $returnArr&#x5B;&quot;debut_dDay&quot;] = $days_since_debut;\n                  $returnArr&#x5B;&quot;anniver_date&quot;] = (new DateTime(&quot;midnight&quot;))-&gt;modify(&#039;+&#039;.($days_since_debut*-1).&#039; day&#039;)-&gt;format(&#039;n\uc6d4 d\uc77c&#039;);\n            }else{\n                  \/\/ \ub370\ubdd4 \ud6c4 (\ub370\ubdd4\uc77c \ud3ec\ud568)\n\n                  \/\/ Calculate the nearest debut anniversary (in days)\n                  $nearest_debut_anniversary = ($days_since_debut % 365) ? 365 - ($days_since_debut % 365) : 0;\n\n                  \/\/ Calculate the year of the nearest debut anniversary\n                  $nearest_debut_anniversary_year = intval($days_since_debut \/ 365) + ($nearest_debut_anniversary === 0 ? 0 : 1);\n\n                  \/\/ Calculate the nearest 100-day anniversary (in days)\n                  $nearest_100_day_anniversary = 100 - (($days_since_debut + 1) % 100);\n                  if($nearest_100_day_anniversary &gt;= 100){\n                        $nearest_100_day_anniversary -= 100;\n                  }\n\n                  \/\/ Calculate the number of the nearest 100-day anniversary\n                  $nearest_100_day_anniversary_number = intval($days_since_debut \/ 100) + 1;\n\n                  $returnArr&#x5B;&quot;debut_dDay&quot;] = $days_since_debut + 1;\n                  $returnArr&#x5B;&quot;anniver_dDay&quot;] = $nearest_debut_anniversary;\n                  $returnArr&#x5B;&quot;what_year_anniver&quot;] = $nearest_debut_anniversary_year;\n                  $returnArr&#x5B;&quot;d100_dDay&quot;] = $nearest_100_day_anniversary;\n                  $returnArr&#x5B;&quot;what_d100_day_anniver&quot;] = $nearest_100_day_anniversary_number * 100;\n\n                  $minimum_evt_dDay = 0;\n                  if($nearest_debut_anniversary &lt; $nearest_100_day_anniversary){\n                        $minimum_evt_dDay = $nearest_debut_anniversary;                        \n                  }else{\n                        $minimum_evt_dDay = $nearest_100_day_anniversary;\n                  }\n                  $returnArr&#x5B;&quot;anniver_date&quot;] = (new DateTime(&quot;midnight&quot;))-&gt;modify(&#039;+&#039;.$minimum_evt_dDay.&#039; day&#039;)-&gt;format(&#039;n\uc6d4 d\uc77c&#039;);\n            }\n      }\n\n      return $returnArr;\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\uc704 \ud568\uc218\ub97c \ucd94\uac00 \uac1c\uc120\ud55c \ud568\uc218 \uc785\ub2c8\ub2e4. (20230222)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[357,8],"tags":[82,341,358,359,360,361,23],"class_list":["post-701","post","type-post","status-publish","format-standard","hentry","category-ai","category-php","tag-82","tag-341","tag-ai","tag-chatgpt","tag-360","tag-function","tag-php"],"modified_by":"\ucc38\ube5b\ubc14\ub2e4","_links":{"self":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=701"}],"version-history":[{"count":3,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":707,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/701\/revisions\/707"}],"wp:attachment":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}