{"id":735,"date":"2025-07-12T02:59:01","date_gmt":"2025-07-12T02:59:01","guid":{"rendered":"https:\/\/easyaccsoft.com\/webdesign\/?p=735"},"modified":"2025-07-12T02:59:01","modified_gmt":"2025-07-12T02:59:01","slug":"function-diagnose_from_json","status":"publish","type":"post","link":"https:\/\/easyaccsoft.com\/webdesign\/2025\/07\/12\/function-diagnose_from_json\/","title":{"rendered":"function diagnose_from_json"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 PHP \u51fd\u6570\uff0c\u7528\u4e8e\uff1a<\/p>\n\n\n\n<p>\u2705 \u4ece <code>diagnosis_rules.json<\/code> \u8bfb\u53d6\u89c4\u5219<br>\u2705 \u81ea\u52a8\u5339\u914d\u7528\u6237\u63d0\u4ea4\u7684\u75c7\u72b6 \/ \u820c\u8c61 \/ \u8109\u8c61<br>\u2705 \u8fd4\u56de\u6700\u5339\u914d\u7684\u4e2d\u533b\u8bc1\u578b\u4e0e\u65b9\u5242<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 \u4e00\u3001\u5339\u914d\u51fd\u6570 <code>diagnose_from_json()<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nfunction diagnose_from_json($user_symptoms, $tongue_input, $pulse_input) {\n    \/\/ \u8bfb\u53d6 JSON \u6587\u4ef6\n    $json = file_get_contents('diagnosis_rules.json');\n    $rules = json_decode($json, true);\n\n    $best_match = null;\n    $max_score = 0;\n\n    foreach ($rules as $rule) {\n        $score = 0;\n\n        \/\/ \u5339\u914d\u75c7\u72b6\uff08\u5173\u952e\u8bcd\u6a21\u7cca\u5339\u914d\uff09\n        foreach ($rule&#91;'symptoms'] as $keyword) {\n            foreach ($user_symptoms as $symptom) {\n                if (strpos($symptom, $keyword) !== false) {\n                    $score++;\n                    break;\n                }\n            }\n        }\n\n        \/\/ \u5339\u914d\u820c\u8c61\uff08\u5b8c\u5168\u5339\u914d\uff09\n        if (!empty($rule&#91;'tongue']) &amp;&amp; $rule&#91;'tongue'] === $tongue_input) {\n            $score++;\n        }\n\n        \/\/ \u5339\u914d\u8109\u8c61\uff08\u5173\u952e\u8bcd\u6a21\u7cca\u5339\u914d\uff09\n        if (!empty($pulse_input) &amp;&amp; is_array($rule&#91;'pulse'])) {\n            foreach ($rule&#91;'pulse'] as $keyword) {\n                foreach ($pulse_input as $p) {\n                    if (strpos($p, $keyword) !== false) {\n                        $score++;\n                        break;\n                    }\n                }\n            }\n        }\n\n        \/\/ \u66f4\u65b0\u6700\u4f73\u5339\u914d\n        if ($score &gt; $max_score) {\n            $max_score = $score;\n            $best_match = $rule;\n        }\n    }\n\n    return $best_match ?: &#91;'diagnosis' =&gt; '\u65e0\u5339\u914d\u8bc1\u578b', 'formula' =&gt; '\u8bf7\u4eba\u5de5\u5224\u65ad'];\n}\n?&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 \u4e8c\u3001\u4f7f\u7528\u65b9\u5f0f\uff08\u793a\u4f8b\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nrequire 'diagnose_function.php'; \/\/ \u5982\u679c\u4f60\u5c06\u4e0a\u9762\u51fd\u6570\u72ec\u7acb\u4e3a diagnose_function.php\n\n\/\/ \u5047\u8bbe\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\n$user_symptoms = &#91;'\u54b3\u55fd', '\u75f0\u591a', '\u53e3\u6e34'];\n$tongue = '\u9ec4\u817b';\n$pulse = &#91;'\u6ed1'];\n\n$result = diagnose_from_json($user_symptoms, $tongue, $pulse);\n\necho \"\u5efa\u8bae\u8bc1\u578b\uff1a{$result&#91;'diagnosis']}&lt;br&gt;\";\necho \"\u63a8\u8350\u65b9\u5242\uff1a{$result&#91;'formula']}\";\n?&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcc1 \u4e09\u3001<code>diagnosis_rules.json<\/code> \u793a\u4f8b\u5185\u5bb9\u683c\u5f0f\uff1a<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n  {\n    \"diagnosis\": \"\u75f0\u70ed\u54b3\u55fd\",\n    \"formula\": \"\u6e05\u91d1\u5316\u75f0\u6c64\",\n    \"symptoms\": &#91;\"\u54b3\", \"\u75f0\"],\n    \"tongue\": \"\u9ec4\u817b\",\n    \"pulse\": &#91;\"\u6ed1\", \"\u6570\"]\n  },\n  ...\n]\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5982\u4f60\u5e0c\u671b\u5c06\u6b64\u529f\u80fd\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udcbb \u96c6\u6210\u5230\u524d\u53f0\u95ee\u8bca\u7cfb\u7edf<\/li>\n\n\n\n<li>\ud83d\udd04 \u81ea\u52a8\u4ece MySQL \u800c\u975e JSON \u83b7\u53d6\u89c4\u5219<\/li>\n\n\n\n<li>\ud83d\udcca \u8fd4\u56de\u591a\u4e2a\u5019\u9009\u8bc1\u578b + \u5339\u914d\u5206\u6570<\/li>\n<\/ul>\n\n\n\n<p>\u6211\u4e5f\u53ef\u4ee5\u7acb\u5373\u6269\u5c55\u4ee5\u4e0a\u529f\u80fd\u3002\u662f\u5426\u9700\u8981\u6211\u7ee7\u7eed\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 PHP \u51fd\u6570\uff0c\u7528\u4e8e\uff1a \u2705 \u4ece diagnosis_rules.json \u8bfb\u53d6\u89c4\u5219\u2705 \u81ea\u52a8\u5339\u914d\u7528\u6237\u63d0\u4ea4\u7684\u75c7\u72b6 \/ \u820c\u8c61 \/ \u8109\u8c61\u2705 \u8fd4\u56de\u6700\u5339\u914d\u7684\u4e2d\u533b\u8bc1\u578b\u4e0e\u65b9\u5242 \u2705 \u4e00\u3001\u5339\u914d\u51fd\u6570 diagnose_from_json() \u2705 \u4e8c\u3001\u4f7f\u7528\u65b9\u5f0f\uff08\u793a\u4f8b\uff09 \ud83d\udcc1 \u4e09\u3001diagnosis_rules.json \u793a\u4f8b\u5185\u5bb9\u683c\u5f0f\uff1a \u5982\u4f60\u5e0c\u671b\u5c06\u6b64\u529f\u80fd\uff1a \u6211\u4e5f\u53ef\u4ee5\u7acb\u5373\u6269\u5c55\u4ee5\u4e0a\u529f\u80fd\u3002\u662f\u5426\u9700\u8981\u6211\u7ee7\u7eed\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-735","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/posts\/735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/comments?post=735"}],"version-history":[{"count":1,"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/posts\/735\/revisions"}],"predecessor-version":[{"id":736,"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/posts\/735\/revisions\/736"}],"wp:attachment":[{"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/media?parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/categories?post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/easyaccsoft.com\/webdesign\/wp-json\/wp\/v2\/tags?post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}