{"id":103,"date":"2009-04-06T22:16:48","date_gmt":"2009-04-06T14:16:48","guid":{"rendered":"http:\/\/www.lmyoaoa.com\/inn\/?p=103"},"modified":"2009-04-07T15:38:39","modified_gmt":"2009-04-07T07:38:39","slug":"%e8%bd%ac%e7%bc%96%e7%a8%8b%e7%9a%84%e4%ba%94%e4%b8%aa%e8%89%af%e5%a5%bd%e4%b9%a0%e6%83%af","status":"publish","type":"post","link":"http:\/\/www.lmyoaoa.com\/inn\/archives\/103\/","title":{"rendered":"[\u8f6c]\u7f16\u7a0b\u7684\u4e94\u4e2a\u826f\u597d\u4e60\u60ef"},"content":{"rendered":"<p>\u8f6c\u7684\uff0c\u65b9\u4fbf\u6211\u81ea\u5df1\u770b\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7<img decoding=\"async\" class=\"xemotion\" src=\"http:\/\/www.lmyoaoa.com\/inn\/wp-content\/plugins\/x-emotions\/emotions\/maomao\/12.gif\" border=\"0\" alt=\"\" \/><\/p>\n<p>\u3000\u3000\u6839\u636e\u5177\u4f53\u7684\u60c5\u51b5\uff0c\u4e00\u822c\u7684\u5f00\u53d1\u4eba\u5458\u5f80\u5f80\u6bd4\u4f18\u79c0\u7684\u5f00\u53d1\u4eba\u5458\u7684\u6548\u7387\u4f4e 10%~20%\u3002\u4f18\u79c0\u7684\u5f00\u53d1\u4eba\u5458\u7684\u6548\u7387\u66f4\u9ad8\uff0c\u56e0\u4e3a\u4ed6\u4eec\u62e5\u6709\u4e30\u5bcc\u7684\u7ecf\u9a8c\u548c\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u3002\u4e0d\u826f\u7684\u7f16\u7a0b\u4e60\u60ef\u5c06\u4f1a\u5f71\u54cd\u5230\u6548\u7387\u3002\u672c\u6587\u901a\u8fc7\u5c55\u793a\u4e00\u4e9b\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\uff0c\u5e2e\u52a9\u60a8\u6210\u4e3a\u66f4\u4f18\u79c0\u7684\u7a0b\u5e8f\u5458\u3002<\/p>\n<p>\u3000\u3000\u8fd9\u4e9b\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u4e0d\u4ec5\u80fd\u63d0\u9ad8\u6548\u7387\uff0c\u8fd8\u80fd\u8ba9\u60a8\u7f16\u5199\u51fa\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u4e2d\u6613\u4e8e\u7ef4\u62a4\u7684\u4ee3\u7801\u3002\u7f16\u5199\u51fa\u6765\u7684\u4ee3\u7801\u53ef\u80fd\u9700\u8981\u5927\u91cf\u7684\u7ef4\u62a4\uff1b\u5e94\u7528\u7a0b\u5e8f\u7684\u7ef4\u62a4\u662f\u4e00\u7b14\u5f88 \u5927\u7684\u5f00\u652f\u3002\u517b\u6210\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u80fd\u591f\u63d0\u9ad8\u8bbe\u8ba1\u8d28\u91cf\uff08\u6bd4\u5982\u6a21\u5757\u5316\uff09\uff0c\u4ece\u800c\u4f7f\u4ee3\u7801\u66f4\u52a0\u5bb9\u6613\u7406\u89e3\uff0c\u56e0\u6b64\u7ef4\u62a4\u5c31\u66f4\u52a0\u5bb9\u6613\uff0c\u540c\u65f6\u4e5f\u964d\u4f4e\u7ef4\u62a4\u6210\u672c\u3002<\/p>\n<p>\u3000\u3000\u4e0d\u826f\u7684\u7f16\u7a0b\u4e60\u60ef\u4f1a\u9020\u6210\u4ee3\u7801\u7f3a\u9677\uff0c\u4f7f\u5176\u96be\u4ee5\u7ef4\u62a4\u548c\u4fee\u6539\uff0c\u5e76\u4e14\u5f88\u53ef\u80fd\u5728\u4fee\u6539\u65f6\u53c8\u5f15\u5165\u5176\u4ed6\u7f3a\u9677\u3002\u4ee5\u4e0b\u662f 5 \u4e2a\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\uff0c\u80fd\u591f\u5e2e\u52a9 PHP \u4ee3\u7801\u907f\u514d\u8fd9\u4e9b\u7f3a\u9677\uff1a<\/p>\n<p>\u3000\u3000\u25c6\u4f7f\u7528\u826f\u597d\u7684\u547d\u540d\u3002<\/p>\n<p>\u3000\u3000\u25c6\u5206\u6210\u66f4\u5c0f\u7684\u90e8\u5206\u3002<\/p>\n<p>\u3000\u3000\u25c6\u4e3a\u4ee3\u7801\u6dfb\u52a0\u6ce8\u91ca\u3002<\/p>\n<p>\u3000\u3000\u25c6\u5904\u7406\u9519\u8bef\u6761\u4ef6\u3002<\/p>\n<p>\u3000\u3000\u25c6\u5207\u5fcc\u4f7f\u7528\u590d\u5236\u7c98\u8d34\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u3000\u3000\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u4e60\u60ef\uff1a<\/p>\n<p>\u3000\u3000\u4f7f\u7528\u826f\u597d\u7684\u547d\u540d<\/p>\n<p>\u3000\u3000\u4f7f\u7528\u826f\u597d\u7684\u547d\u540d\u662f\u6700\u91cd\u8981\u7684\u7f16\u7a0b\u4e60\u60ef\uff0c\u56e0\u4e3a\u63cf\u8ff0\u6027\u5f3a\u7684\u540d\u79f0\u8ba9\u4ee3\u7801\u66f4\u52a0\u5bb9\u6613\u9605\u8bfb\u548c\u7406\u89e3\u3002\u4ee3\u7801\u662f\u5426\u597d\u7406\u89e3\u53d6\u51b3\u4e8e\u662f\u5426\u80fd\u5728\u672a\u6765\u7ef4\u62a4\u5b83\u3002\u5373\u4fbf\u4ee3\u7801\u4e0d\u5e26\u6709\u6ce8\u91ca\uff0c\u5982\u679c\u5b83\u5f88\u5bb9\u6613\u7406\u89e3\uff0c\u5c06\u5927\u5927\u65b9\u4fbf\u65e5\u540e\u7684\u66f4\u6539\u3002\u8fd9\u4e2a\u4e60\u60ef\u7684\u76ee\u6807\u662f\u8ba9\u60a8\u7f16\u5199\u7684\u4ee3\u7801\u50cf\u4e66\u672c\u4e00\u6837\u5bb9\u6613\u9605\u8bfb\u548c\u7406\u89e3\u3002<\/p>\n<p>\u3000\u3000\u4e0d\u826f\u4e60\u60ef\uff1a\u542b\u7cca\u7684\u6216\u65e0\u610f\u4e49\u7684\u540d\u79f0<\/p>\n<p>\u3000\u3000\u6e05\u5355 1 \u4e2d\u7684\u4ee3\u7801\u5305\u542b\u8fc7\u77ed\u7684\u53d8\u91cf\u540d\u3001\u96be\u4ee5\u8fa8\u8ba4\u7684\u7f29\u5199\u8bcd\uff0c\u5e76\u4e14\u65b9\u6cd5\u540d\u4e0d\u80fd\u53cd\u6620\u8be5\u65b9\u6cd5\u7684\u529f\u80fd\u3002\u5982\u679c\u65b9\u6cd5\u540d\u7ed9\u4eba\u7684\u611f\u89c9\u662f\u5b83\u5e94\u8be5\u505a\u8fd9\u4ef6\u4e8b\u60c5\uff0c\u800c\u5b9e\u9645\u4e2d\u5b83\u5374\u505a\u53e6\u5916\u7684\u4e8b\u60c5\uff0c\u8fd9\u5c06\u5e26\u6765\u4e25\u91cd\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u5b83\u4f1a\u8bef\u5bfc\u4eba\u3002<\/p>\n<p><a name=\"listing1\"><strong>\u6e05\u5355 1. \u4e0d\u826f\u4e60\u60ef\uff1a\u542b\u7cca\u7684\u6216\u65e0\u610f\u4e49\u7684\u540d\u79f0<\/strong><\/a><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\nfunction getNBDay($d)\r\n{\r\n    switch($d) {\r\n        case 5:\r\n        case 6:\r\n        case 7:\r\n            return 1;\r\n        default:\r\n            return ($d + 1);\r\n    }\r\n}\r\n\r\n$day = 5;\r\n\r\n$nextDay = getNBDay($day);\r\n\r\necho (\"Next day is: \" . $nextDay . \"\\n\");\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"N10094\"><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u826f\u597d\u4e60\u60ef\uff1a\u8bf4\u660e\u6027\u5f3a\u5e76\u4e14\u7b80\u6d01\u7684\u540d\u79f0<\/span><\/strong><\/span><\/a><\/p>\n<p>\u6e05\u5355 2 \u4e2d\u7684\u4ee3\u7801\u4f53\u73b0\u4e86\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u3002\u65b0\u7684\u65b9\u6cd5\u540d\u5177\u6709\u5f88\u5f3a\u7684\u8bf4\u660e\u6027\uff0c\u53cd\u6620\u4e86\u65b9\u6cd5\u7684\u7528\u9014\u3002\u540c\u6837\uff0c\u66f4\u6539\u540e\u7684\u53d8\u91cf\u540d\u4e5f\u66f4\u5177\u8bf4\u660e\u6027\u3002\u60df\u4e00\u7684\u4fdd\u6301\u6700\u77ed\u7684\u53d8\u91cf\u662f <code>$i<\/code>\uff0c\u5728\u672c\u6e05\u5355\u4e2d\uff0c\u5b83\u662f\u4e00\u4e2a\u5faa\u73af\u53d8\u91cf\u3002\u5c3d\u7ba1\u5f88\u591a\u4eba\u4e0d\u8d5e\u540c\u4f7f\u7528\u8fc7\u77ed\u7684\u540d\u79f0\uff0c\u4f46\u5728\u5faa\u73af\u53d8\u91cf\u4e2d\u4f7f\u7528\u8fd8\u662f\u53ef\u4ee5\u63a5\u53d7\u7684\uff08\u751a\u81f3\u6709\u597d\u5904\uff09\uff0c\u56e0\u4e3a\u5b83\u660e\u786e\u8868\u660e\u4e86\u4ee3\u7801\u7684\u529f\u80fd\u3002<br \/>\n<strong>\u6e05\u5355 2. \u826f\u597d\u4e60\u60ef\uff1a\u8bf4\u660e\u6027\u5f3a\u5e76\u4e14\u7b80\u6d01\u7684\u540d\u79f0<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\ndefine ('MONDAY', 1);\r\ndefine ('TUESDAY', 2);\r\ndefine ('WEDNESDAY', 3);\r\ndefine ('THURSDAY', 4);\r\ndefine ('FRIDAY', 5);\r\ndefine ('SATURDAY', 6);\r\ndefine ('SUNDAY', 7);\r\n\r\n\/*\r\n *\r\n * @param $dayOfWeek\r\n * @return int Day of week, with 1 being Monday and so on.\r\n *\/\r\nfunction findNextBusinessDay($dayOfWeek)\r\n{\r\n    $nextBusinessDay = $dayOfWeek;\r\n\r\n    switch($dayOfWeek) {\r\n        case FRIDAY:\r\n        case SATURDAY:\r\n        case SUNDAY:\r\n            $nextBusinessDay = MONDAY;\r\n            break;\r\n        default:\r\n            $nextBusinessDay += 1;\r\n            break;\r\n    }\r\n\r\n    return $nextBusinessDay;\r\n}\r\n\r\n$day = FRIDAY;\r\n\r\n$nextBusDay = findNextBusinessDay($day);\r\n\r\necho (\"Next day is:\" . $nextBusDay . \"\\n\");\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u4eec\u9f13\u52b1\u60a8\u5c06\u5927\u7684\u6761\u4ef6\u62c6\u5206\u4e3a\u4e00\u4e2a\u65b9\u6cd5\uff0c\u7136\u540e\u7528\u80fd\u591f\u63cf\u8ff0\u8be5\u6761\u4ef6\u7684\u540d\u5b57\u547d\u540d\u65b9\u6cd5\u3002\u8fd9\u4e2a\u6280\u5de7\u80fd\u591f\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u5e76\u4e14\u80fd\u591f\u5c06\u6761\u4ef6\u5177\u4f53\u5316\uff0c\u4f7f\u4e4b\u80fd\u591f\u88ab\u63d0\u53d6\u751a\u81f3\u91cd\u7528\u3002\u5982\u679c\u6761\u4ef6\u53d1\u751f\u53d8\u5316\uff0c\u66f4\u65b0\u65b9\u6cd5\u4e5f\u5f88\u5bb9\u6613\u3002\u56e0\u4e3a\u65b9\u6cd5\u62e5\u6709\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u540d\u5b57\uff0c\u6240\u4ee5\u5b83\u80fd\u53cd\u6620\u4ee3\u7801\u7684\u7528\u9014\uff0c\u8ba9\u4ee3\u7801\u66f4\u5bb9\u6613\u9605\u8bfb\u3002<\/p>\n<p>\u4e13\u5fc3\u89e3\u51b3\u4e00\u4e2a\u95ee\u9898\u4e4b\u540e\u518d\u7ee7\u7eed\u7f16\u7a0b\uff0c\u8fd9\u6837\u4f1a\u8ba9\u60a8\u66f4\u8f7b\u677e\u3002\u5728\u89e3\u51b3\u4e00\u4e2a\u7d27\u6025\u7684\u95ee\u9898\u65f6\uff0c\u5982\u679c\u7ee7\u7eed\u7f16\u7a0b\uff0c\u4f1a\u4f7f\u51fd\u6570\u8d8a\u6765\u8d8a\u957f\u3002\u4ece\u957f\u8fdc\u6765\u8bf4\uff0c\u8fd9\u5e76\u4e0d\u662f\u4e00\u4e2a\u95ee\u9898\uff0c\u4f46\u60a8\u8981\u8bb0\u5f97\u56de\u8fc7\u5934\u6765\u5c06\u5b83\u91cd\u6784\u4e3a\u66f4\u5c0f\u7684\u90e8\u5206\u3002<\/p>\n<p>\u91cd\u6784\u662f\u4e2a\u4e0d\u9519\u7684\u4e3b\u610f\uff0c\u4f46\u60a8\u5e94\u8be5\u517b\u6210\u7f16\u5199\u66f4\u77ed\u3001\u529f\u80fd\u66f4\u96c6\u4e2d\u7684\u4ee3\u7801\u3002\u77ed\u7684\u65b9\u6cd5\u80fd\u591f\u5728\u4e00\u4e2a\u7a97\u53e3\u4e2d\u4e00\u6b21\u770b\u5b8c\uff0c\u5e76\u4e14\u5bb9\u6613\u7406\u89e3\u3002\u5982\u679c\u65b9\u6cd5\u8fc7\u957f\uff0c\u4e0d\u80fd\u5728\u4e00\u4e2a\u7a97\u53e3\u4e2d\u4e00\u6b21\u770b\u5b8c\uff0c\u90a3\u4e48\u5b83\u5c31\u53d8\u5f97\u4e0d\u5bb9\u6613\u7406\u89e3\uff0c\u56e0\u4e3a\u60a8\u4e0d\u80fd\u5feb\u901f\u5730\u4ece\u5934\u5230\u5c3e\u4e86\u89e3\u5b83\u7684\u6574\u4e2a\u601d\u8def\u3002<\/p>\n<p>\u6784\u5efa\u65b9\u6cd5\u65f6\uff0c\u60a8\u5e94\u8be5\u517b\u6210\u8fd9\u6837\u7684\u4e60\u60ef\uff0c\u8ba9\u6bcf\u4e2a\u65b9\u6cd5\u53ea\u5b8c\u6210\u4e00\u4ef6\u4e8b\u60c5\u3002\u8fd9\u4e2a\u4e60\u60ef\u5f88\u597d\uff0c\u56e0\u4e3a\uff1a\u9996\u5148\uff0c\u5982\u679c\u65b9\u6cd5\u53ea\u5b8c\u6210\u4e00\u4ef6\u4e8b\u60c5\uff0c\u90a3\u4e48\u5b83\u5c31\u66f4\u5bb9\u6613\u88ab\u91cd\u7528\uff1b\u5176\u6b21\uff0c\u8fd9\u6837\u7684\u65b9\u6cd5\u5bb9\u6613\u6d4b\u8bd5\uff1b\u7b2c\u4e09\uff0c\u8fd9\u6837\u7684\u65b9\u6cd5\u4fbf\u4e8e\u7406\u89e3\u548c\u66f4\u6539\u3002<\/p>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u4e0d\u826f\u4e60\u60ef\uff1a\u8fc7\u957f\u7684\u65b9\u6cd5\uff08\u5b8c\u6210\u5f88\u591a\u4ef6\u4e8b\u60c5\uff09<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 3 \u5c55\u793a\u4e86\u4e00\u4e2a\u5f88\u957f\u7684\u51fd\u6570\uff0c\u5176\u4e2d\u5b58\u5728\u5f88\u591a\u95ee\u9898\u3002\u5b83\u5b8c\u6210\u5f88\u591a\u4ef6\u4e8b\u60c5\uff0c\u56e0\u6b64\u4e0d\u591f\u7d27\u51d1\u3002\u5b83\u4e5f\u4e0d\u4fbf\u4e8e\u9605\u8bfb\u3001\u8c03\u8bd5\u548c\u6d4b\u8bd5\u3002\u5b83\u8981\u505a\u7684\u4e8b\u60c5\u5305\u62ec\u904d\u5386\u4e00\u4e2a\u6587\u4ef6\u3001\u6784\u5efa\u4e00\u4e2a\u5217\u8868\u3001\u4e3a\u6bcf\u4e2a\u5bf9\u8c61\u8d4b\u503c\u3001\u6267\u884c\u8ba1\u7b97\u7b49\u7b49\u3002<br \/>\n<strong>\u6e05\u5355 3. \u4e0d\u826f\u4e60\u60ef\uff1a\u8fc7\u957f\u7684\u51fd\u6570<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\nfunction writeRssFeed($user)\r\n{\r\n    \/\/ Get the DB connection information\r\n\r\n    \/\/ look up the user's preferences...\r\n    $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')\r\n        OR die(mysql_error());\r\n\r\n    \/\/ Query\r\n    $perfsQuery = sprintf(\"SELECT max_stories FROM user_perfs WHERE user= '%s'\",\r\n            mysql_real_escape_string($user));\r\n\r\n    $result = mysql_query($query, $link);\r\n\r\n    $max_stories = 25; \/\/ default it to 25;\r\n\r\n    if ($row = mysql_fetch_assoc($result)) {\r\n        $max_stories = $row['max_stories'];\r\n    }\r\n\r\n    \/\/ go get my data\r\n    $perfsQuery = sprintf(\"SELECT * FROM stories WHERE post_date = '%s'\",\r\n            mysql_real_escape_string());\r\n\r\n    $result = mysql_query($query, $link); \r\n\r\n    $feed = \"&lt;rss version=\\\"2.0\\\"&gt;\" .\r\n        \"&lt;channel&gt;\" .\r\n        \"&lt;title&gt;My Great Feed&lt;\/title&gt;\" .\r\n        \"&lt;link&gt;http:\/\/www.example.com\/feed.xml&lt;\/link&gt;\" .\r\n        \"&lt;description&gt;The best feed in the world&lt;\/description&gt;\" .\r\n        \"&lt;language&gt;en-us&lt;\/language&gt;\" .\r\n        \"&lt;pubDate&gt;Tue, 20 Oct 2008 10:00:00 GMT&lt;\/pubDate&gt;\" .\r\n        \"&lt;lastBuildDate&gt;Tue, 20 Oct 2008 10:00:00 GMT&lt;\/lastBuildDate&gt;\" .\r\n        \"&lt;docs&gt;http:\/\/www.example.com\/rss&lt;\/docs&gt;\" .\r\n        \"&lt;generator&gt;MyFeed Generator&lt;\/generator&gt;\" .\r\n        \"&lt;managingEditor&gt;editor@example.com&lt;\/managingEditor&gt;\" .\r\n        \"&lt;webMaster&gt;webmaster@example.com&lt;\/webMaster&gt;\" .\r\n        \"&lt;ttl&gt;5&lt;\/ttl&gt;\";\r\n\r\n        \/\/ build the feed...\r\n        while ($row = mysql_fetch_assoc($result)) {\r\n            $title = $row['title'];\r\n            $link = $row['link'];\r\n            $description = $row['description'];\r\n            $date = $row['date'];\r\n            $guid = $row['guid'];\r\n\r\n            $feed .= \"&lt;item&gt;\";\r\n            $feed .= \"&lt;title&gt;\" . $title . \"&lt;\/title&gt;\";\r\n            $feed .= \"&lt;link&gt;\" . $link . \"&lt;\/link&gt;\";\r\n            $feed .= \"&lt;description&gt; \" . $description . \"&lt;\/description&gt;\";\r\n            $feed .= \"&lt;pubDate&gt;\" . $date . \"&lt;\/pubDate&gt;\";\r\n            $feed .= \"&lt;guid&gt;\" . $guid . \"&lt;\/guid&gt;\";\r\n            $feed .= \"&lt;\/item&gt;\";\r\n        }\r\n\r\n        $feed .= \"&lt;\/rss\";\r\n\r\n        \/\/ write the feed out to the server...\r\n        echo($feed);\r\n\r\n}\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5982\u679c\u591a\u7f16\u5199\u51e0\u4e2a\u8fd9\u6837\u7684\u65b9\u6cd5\uff0c\u7ef4\u62a4\u5c31\u6210\u4e86\u771f\u6b63\u7684\u96be\u9898\u4e86\u3002<\/p>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u826f\u597d\u4e60\u60ef\uff1a\u6613\u7ba1\u7406\u3001\u529f\u80fd\u4e13\u4e00\u7684\u65b9\u6cd5<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 4 \u5c06\u539f\u6765\u7684\u65b9\u6cd5\u6539\u5199\u4e3a\u66f4\u52a0\u7d27\u51d1\u3001\u6613\u8bfb\u7684\u65b9\u6cd5\u3002\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5c06\u4e00\u4e2a\u5f88\u957f\u7684\u65b9\u6cd5\u5206\u89e3\u4e3a\u51e0\u4e2a\u77ed\u65b9\u6cd5\uff0c\u5e76\u4e14\u8ba9\u6bcf\u4e2a\u77ed\u65b9\u6cd5\u8d1f\u8d23\u4e00\u4ef6\u4e8b\u60c5\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5bf9\u5c06\u6765\u7684\u91cd\u7528\u548c\u6d4b\u8bd5\u90fd\u662f\u5927\u6709\u88e8\u76ca\u7684\u3002<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\nfunction createRssHeader()\r\n{\r\n    return \"&lt;rss version=\\\"2.0\\\"&gt;\" .\r\n        \"&lt;channel&gt;\" .\r\n        \"&lt;title&gt;My Great Feed&lt;\/title&gt;\" .\r\n        \"&lt;link&gt;http:\/\/www.example.com\/feed.xml&lt;\/link&gt;\" .\r\n        \"&lt;description&gt;The best feed in the world&lt;\/description&gt;\" .\r\n        \"&lt;language&gt;en-us&lt;\/language&gt;\" .\r\n        \"&lt;pubDate&gt;Tue, 20 Oct 2008 10:00:00 GMT&lt;\/pubDate&gt;\" .\r\n        \"&lt;lastBuildDate&gt;Tue, 20 Oct 2008 10:00:00 GMT&lt;\/lastBuildDate&gt;\" .\r\n        \"&lt;docs&gt;http:\/\/www.example.com\/rss&lt;\/docs&gt;\" .\r\n        \"&lt;generator&gt;MyFeed Generator&lt;\/generator&gt;\" .\r\n        \"&lt;managingEditor&gt;editor@example.com&lt;\/managingEditor&gt;\" .\r\n        \"&lt;webMaster&gt;webmaster@example.com&lt;\/webMaster&gt;\" .\r\n        \"&lt;ttl&gt;5&lt;\/ttl&gt;\";\r\n}\r\n\r\nfunction createRssFooter()\r\n{\r\n    return \"&lt;\/channel&gt;&lt;\/rss&gt;\";\r\n}\r\n\r\nfunction createRssItem($title, $link, $desc, $date, $guid)\r\n{\r\n    $item .= \"&lt;item&gt;\";\r\n    $item .= \"&lt;title&gt;\" . $title . \"&lt;\/title&gt;\";\r\n    $item .= \"&lt;link&gt;\" . $link . \"&lt;\/link&gt;\";\r\n    $item .= \"&lt;description&gt; \" . $description . \"&lt;\/description&gt;\";\r\n    $item .= \"&lt;pubDate&gt;\" . $date . \"&lt;\/pubDate&gt;\";\r\n    $item .= \"&lt;guid&gt;\" . $guid . \"&lt;\/guid&gt;\";\r\n    $item .= \"&lt;\/item&gt;\";\r\n    return $item;\r\n}\r\n\r\nfunction getUserMaxStories($db_link, $default)\r\n{\r\n    $perfsQuery = sprintf(\"SELECT max_stories FROM user_perfs WHERE user= '%s'\",\r\n            mysql_real_escape_string($user));\r\n\r\n    $result = mysql_query($perfsQuery, $db_link);\r\n\r\n    $max_stories = $default;\r\n\r\n    if ($row = mysql_fetch_assoc($result)) {\r\n        $max_stories = $row['max_stories'];\r\n    } \r\n\r\n    return $max_stories;\r\n}\r\n\r\nfunction writeRssFeed($user)\r\n{\r\n    \/\/ Get the DB connection information\r\n    $settings = parse_ini_file(\"rss_server.ini\");\r\n\r\n    \/\/ look up the user's preferences...\r\n    $link = mysql_connect($settings['db_host'], $settings['user'],\r\n        $settings['password']) OR die(mysql_error());\r\n\r\n    $max_stories = getUserMaxStories($link, 25);\r\n\r\n    \/\/ go get my data\r\n    $newsQuery = sprintf(\"SELECT * FROM stories WHERE post_date = '%s'\",\r\n            mysql_real_escape_string(time()));\r\n\r\n    $result = mysql_query($newsQuery, $link); \r\n\r\n    $feed = createRssHeader();\r\n\r\n    $i = 0;\r\n    \/\/ build the feed...\r\n    while ($row = mysql_fetch_assoc($result)) {\r\n        if ($i &lt; $max_stories) {\r\n            $title = $row['title'];\r\n            $link = $row['link'];\r\n            $description = $row['description'];\r\n            $date = $row['date'];\r\n            $guid = $row['guid'];\r\n\r\n            $feed .= createRssItem($title, $link, $description, $date, $guid);\r\n\r\n            $i++;\r\n        } else {\r\n            break;\r\n        }\r\n    }\r\n\r\n    mysql_close($link);\r\n\r\n    $feed .= createRssFooter();\r\n\r\n    \/\/ write the feed out to the server...\r\n    echo($feed);\r\n}\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5c06\u957f\u65b9\u6cd5\u62c6\u5206\u4e3a\u77ed\u65b9\u6cd5\u4e5f\u662f\u6709\u9650\u5236\u7684\uff0c\u8fc7\u5ea6\u62c6\u5206\u5c06\u9002\u5f97\u5176\u53cd\u3002\u56e0\u6b64\uff0c\u4e0d\u8981\u6ee5\u7528\u8fd9\u4e2a\u826f\u597d\u7684\u4e60\u60ef\u3002\u5c06\u4ee3\u7801\u5206\u6210\u5927\u91cf\u7684\u7247\u6bb5\u5c31\u50cf\u6ca1\u6709\u62c6\u5206\u957f\u4ee3\u7801\u4e00\u6837\uff0c\u90fd\u4f1a\u9020\u6210\u9605\u8bfb\u56f0\u96be<\/p>\n<p><span class=\"atitle\">\u4e3a\u4ee3\u7801\u6dfb\u52a0\u6ce8\u91ca<\/span><\/p>\n<p>\u8981\u4e3a\u4ee3\u7801\u6dfb\u52a0\u826f\u597d\u7684\u6ce8\u91ca\u6709\u65f6\u4f3c\u4e4e\u548c\u7f16\u5199\u4ee3\u7801\u4e00\u6837\u96be\u3002\u8981\u4e86\u89e3\u5e94\u8be5\u4e3a\u54ea\u4e9b\u5185\u5bb9\u6dfb\u52a0\u6ce8\u91ca\u5e76\u4e0d\u5bb9\u6613\uff0c\u56e0\u4e3a\u6211\u4eec\u5e38\u5e38\u503e\u5411\u4e8e\u6ce8\u91ca\u4ee3\u7801\u5f53\u524d\u505a\u7684\u4e8b\u60c5\u3002\u6ce8\u91ca\u4ee3\u7801\u7684\u76ee\u7684\u662f\u4e0d\u9519\u7684\u4e3b\u610f\u3002\u5728\u51fd\u6570\u7684\u4e0d\u662f\u5f88\u660e\u663e\u7684\u5934\u90e8\u4ee3\u7801\u5757\u4e2d\uff0c\u544a\u8bc9\u8bfb\u8005\u65b9\u6cd5\u7684\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u4ee5\u53ca\u65b9\u6cd5\u7684\u6700\u521d\u76ee\u6807\u3002<\/p>\n<p>\u6ce8\u91ca\u4ee3\u7801\u5f53\u524d\u505a\u4ec0\u4e48\u662f\u5f88\u5e38\u89c1\u7684\uff0c\u4f46\u8fd9\u662f\u4e0d\u5fc5\u8981\u7684\u3002\u5982\u679c\u4ee3\u7801\u5f88\u590d\u6742\uff0c\u4e0d\u5f97\u4e0d\u6ce8\u91ca\u5b83\u5f53\u524d\u5728\u505a\u4ec0\u4e48\uff0c\u8fd9\u5c06\u6697\u793a\u60a8\u5e94\u8be5\u91cd\u5199\u4ee3\u7801\uff0c\u8ba9\u5b83\u66f4\u5bb9\u6613\u7406\u89e3\u3002\u5b66\u4f1a\u4f7f\u7528\u826f\u597d\u7684\u540d\u79f0\u548c\u66f4\u77ed\u7684\u65b9\u6cd5\uff0c\u5728\u4e0d\u63d0\u4f9b\u6ce8\u91ca\u8bf4\u660e\u5176\u7528\u9014\u7684\u60c5\u51b5\u4e0b\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u4e0d\u826f\u4e60\u60ef\uff1a\u51fd\u6570\u6ce8\u91ca\u8fc7\u591a\u6216\u4e0d\u8db3<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 5 \u4e2d\u7684\u6ce8\u91ca\u4ec5\u544a\u8bc9\u8bfb\u8005\u4ee3\u7801\u5728\u505a\u4ec0\u4e48 \u2014 \u5b83\u6b63\u5728\u901a\u8fc7\u4e00\u4e2a\u5faa\u73af\u8fdb\u884c\u8fed\u4ee3\u6216\u6dfb\u52a0\u4e00\u4e2a\u6570\u5b57\u3002\u4f46\u5b83\u5ffd\u7565\u4e86\u5b83<em>\u4e3a\u4ec0\u4e48<\/em> \u505a\u5f53\u524d\u7684\u5de5\u4f5c\u3002\u8fd9\u4f7f\u7ef4\u62a4\u8be5\u4ee3\u7801\u7684\u4eba\u5458\u4e0d\u77e5\u9053\u662f\u5426\u53ef\u4ee5\u5b89\u5168\u5730\u66f4\u6539\u4ee3\u7801\uff08\u4e0d\u5f15\u5165\u65b0\u7f3a\u9677\uff09\u3002<br \/>\n<strong>\u6e05\u5355 5. \u4e0d\u826f\u4e60\u60ef\uff1a\u51fd\u6570\u6ce8\u91ca\u8fc7\u591a\u6216\u4e0d\u8db3<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\nclass ResultMessage\r\n{\r\n    private $severity;\r\n    private $message;\r\n\r\n    public function __construct($sev, $msg)\r\n    {\r\n        $this-&gt;severity = $sev;\r\n        $this-&gt;message = $msg;\r\n    }\r\n\r\n    public function getSeverity()\r\n    {\r\n        return $this-&gt;severity;\r\n    }\r\n\r\n    public function setSeverity($severity)\r\n    {\r\n        $this-&gt;severity = $severity;\r\n    }\r\n\r\n    public function getMessage()\r\n    {\r\n        return $this-&gt;message;\r\n    }\r\n\r\n    public function setMessage($msg)\r\n    {\r\n        $this-&gt;message = $msg;\r\n    }\r\n}\r\n\r\nfunction cntMsgs($messages)\r\n{\r\n    $n = 0;\r\n    \/* iterate through the messages... *\/\r\n    foreach($messages as $m) {\r\n        if ($m-&gt;getSeverity() == 'Error') {\r\n            $n++; \/\/ add one to the result;\r\n        }\r\n    }\r\n    return $n;\r\n}\r\n\r\n$messages = array(new ResultMessage(\"Error\", \"This is an error!\"),\r\n    new ResultMessage(\"Warning\", \"This is a warning!\"),\r\n    new ResultMessage(\"Error\", \"This is another error!\"));\r\n\r\n$errs = cntMsgs($messages);\r\n\r\necho(\"There are \" . $errs . \" errors in the result.\\n\");\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u826f\u597d\u4e60\u60ef\uff1a\u5e26\u6ce8\u91ca\u7684\u51fd\u6570\u548c\u7c7b<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 6 \u4e2d\u7684\u6ce8\u91ca\u544a\u8bc9\u8bfb\u8005\u7c7b\u548c\u65b9\u6cd5\u7684\u76ee\u7684\u3002\u8be5\u6ce8\u91ca\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48\u4ee3\u7801\u5728\u505a\u5f53\u524d\u7684\u5de5\u4f5c\uff0c\u8fd9\u5bf9\u672a\u6765\u7ef4\u62a4\u4ee3\u7801\u5341\u5206\u6709\u7528\u3002\u53ef\u80fd\u9700\u8981\u6839\u636e\u6761\u4ef6\u53d8\u66f4\u800c\u4fee\u6539\u4ee3\u7801\uff0c\u5982\u679c\u80fd\u591f\u8f7b\u677e\u4e86\u89e3\u4ee3\u7801\u7684\u76ee\u7684\uff0c\u5219\u4fee\u6539\u8d77\u6765\u5f88\u5bb9\u6613\u3002<br \/>\n<strong>\u6e05\u5355 6. \u826f\u597d\u4e60\u60ef\uff1a\u5e26\u6ce8\u91ca\u7684\u51fd\u6570\u548c\u7c7b<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\/**\r\n * The ResultMessage class holds a message that can be returned\r\n * as a result of a process. The message has a severity and\r\n * message.\r\n *\r\n * @author nagood\r\n *\r\n *\/\r\nclass ResultMessage\r\n{\r\n    private $severity;\r\n    private $message;\r\n\r\n    \/**\r\n     * Constructor for the ResultMessage that allows you to assign\r\n     * severity and message.\r\n     * @param $sev See {@link getSeverity()}\r\n     * @param $msg\r\n     * @return unknown_type\r\n     *\/\r\n    public function __construct($sev, $msg)\r\n    {\r\n        $this-&gt;severity = $sev;\r\n        $this-&gt;message = $msg;\r\n    }\r\n\r\n    \/**\r\n     * Returns the severity of the message. Should be one\r\n     * \"Information\", \"Warning\", or \"Error\".\r\n     * @return string Message severity\r\n     *\/\r\n    public function getSeverity()\r\n    {\r\n        return $this-&gt;severity;\r\n    }\r\n\r\n    \/**\r\n     * Sets the severity of the message\r\n     * @param $severity\r\n     * @return void\r\n     *\/\r\n    public function setSeverity($severity)\r\n    {\r\n        $this-&gt;severity = $severity;\r\n    }\r\n\r\n    public function getMessage()\r\n    {\r\n        return $this-&gt;message;\r\n    }\r\n\r\n    public function setMessage($msg)\r\n    {\r\n        $this-&gt;message = $msg;\r\n    }\r\n}\r\n\r\n\/*\r\n * Counts the messages with the given severity in the array\r\n * of messages.\r\n *\r\n * @param $messages An array of ResultMessage\r\n * @return int Count of messages with a severity of \"Error\"\r\n *\/\r\nfunction countErrors($messages)\r\n{\r\n    $matchingCount = 0;\r\n    foreach($messages as $m) {\r\n        if ($m-&gt;getSeverity() == \"Error\") {\r\n            $matchingCount++;\r\n        }\r\n    }\r\n    return $matchingCount;\r\n}\r\n\r\n$messages = array(new ResultMessage(\"Error\", \"This is an error!\"),\r\n    new ResultMessage(\"Warning\", \"This is a warning!\"),\r\n    new ResultMessage(\"Error\", \"This is another error!\"));\r\n\r\n$errs = countErrors($messages);\r\n\r\necho(\"There are \" . $errs . \" errors in the result.\\n\");\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"atitle\">\u5904\u7406\u9519\u8bef<\/span><\/p>\n<p>\u6839\u636e\u5927\u4f17\u7684\u7ecf\u9a8c\uff0c\u5982\u679c\u8981\u7f16\u5199\u5065\u58ee\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u9519\u8bef\u5904\u7406\u8981\u9075\u5faa 80\/20 \u89c4\u5219\uff1a80% \u7684\u4ee3\u7801\u7528\u4e8e\u5904\u7406\u5f02\u5e38\u548c\u9a8c\u8bc1\uff0c20% \u7684\u4ee3\u7801\u7528\u4e8e\u5b8c\u6210\u5b9e\u9645\u5de5\u4f5c\u3002\u5728\u7f16\u5199<em>\u7a0b\u5e8f\u7684\u57fa\u672c\u903b\u8f91\uff08happy-path\uff09\u4ee3\u7801<\/em> \u65f6\u7ecf\u5e38\u8fd9\u6837\u505a\u3002\u8fd9\u610f\u5473\u7740\u7f16\u5199\u9002\u7528\u4e8e\u57fa\u672c\u6761\u4ef6\u7684\u4ee3\u7801\uff0c\u5373\u6240\u6709\u7684\u6570\u636e\u90fd\u662f\u53ef\u7528\u7684\uff0c\u6240\u6709\u7684\u6761\u4ef6\u7b26\u5408\u9884\u671f\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u4e2d\u53ef\u80fd\u5f88\u8106\u5f31\u3002\u53e6\u4e00\u4e2a\u6781\u7aef\u662f\uff0c\u751a\u81f3\u9700\u8981\u82b1\u5927\u91cf\u65f6\u95f4\u4e3a\u4ece\u672a\u9047\u5230\u8fc7\u7684\u6761\u4ef6\u7f16\u5199\u4ee3\u7801\u3002<\/p>\n<p>\u8fd9\u4e00\u4e60\u60ef\u8981\u6c42\u60a8\u7f16\u5199\u8db3\u591f\u7684\u9519\u8bef\u5904\u7406\u4ee3\u7801\uff0c\u800c\u4e0d\u662f\u7f16\u5199\u5bf9\u4ed8\u6240\u6709\u9519\u8bef\u7684\u4ee3\u7801\uff0c\u4ee5\u81f4\u4ee3\u7801\u8fdf\u8fdf\u4e0d\u80fd\u5b8c\u6210\u3002<\/p>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u4e0d\u826f\u4e60\u60ef\uff1a\u6839\u672c\u6ca1\u6709\u9519\u8bef\u5904\u7406\u4ee3\u7801<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 7 \u4e2d\u7684\u4ee3\u7801\u6f14\u793a\u4e86\u4e24\u4e2a\u4e0d\u826f\u4e60\u60ef\u3002\u7b2c\u4e00\uff0c\u6ca1\u6709\u68c0\u67e5\u8f93\u5165\u7684\u53c2\u6570\uff0c\u5373\u4f7f\u77e5\u9053\u5904\u4e8e\u67d0\u4e9b\u72b6\u6001\u7684\u53c2\u6570\u4f1a\u9020\u6210\u65b9\u6cd5\u51fa\u73b0\u5f02\u5e38\u3002\u7b2c\u4e8c\uff0c\u4ee3\u7801\u8c03\u7528\u4e00\u4e2a\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\u7684\u65b9\u6cd5\uff0c\u4f46\u6ca1\u6709\u5904\u7406\u8be5\u5f02\u5e38\u3002\u5f53\u53d1\u751f\u95ee\u9898\u65f6\uff0c\u4ee3\u7801\u7684\u4f5c\u8005\u6216\u7ef4\u62a4\u8be5\u4ee3\u7801\u7684\u4eba\u5458\u53ea\u80fd\u731c\u6d4b\u95ee\u9898\u7684\u6839\u6e90\u3002<br \/>\n<strong>\u6e05\u5355 7. \u4e0d\u826f\u4e60\u60ef\uff1a\u4e0d\u5904\u7406\u9519\u8bef\u6761\u4ef6<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\n\/\/ Get the actual name of the\r\nfunction convertDayOfWeekToName($day)\r\n{\r\n    $dayNames = array(\r\n    \"Sunday\",\r\n    \"Monday\",\r\n    \"Tuesday\",\r\n    \"Wednesday\",\r\n    \"Thursday\",\r\n    \"Friday\",\r\n    \"Saturday\");\r\n    return $dayNames[$day];\r\n}\r\n\r\necho(\"The name of the 0 day is:  \" . convertDayOfWeekToName(0) . \"\\n\");\r\necho(\"The name of the 10 day is:  \" . convertDayOfWeekToName(10) . \"\\n\");\r\necho(\"The name of the 'orange' day is:  \" . convertDayOfWeekToName('orange') . \"\\n\");\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u826f\u597d\u4e60\u60ef\uff1a\u5904\u7406\u5f02\u5e38<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 8 \u5c55\u793a\u4e86\u4ee5\u6709\u610f\u4e49\u7684\u65b9\u5f0f\u629b\u51fa\u548c\u5904\u7406\u5f02\u5e38\u3002\u989d\u5916\u7684\u9519\u8bef\u5904\u7406\u4e0d\u4ec5\u4f7f\u4ee3\u7801\u66f4\u52a0\u5065\u58ee\uff0c\u5b83\u8fd8\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u4f7f\u4ee3\u7801\u66f4\u5bb9\u6613\u7406\u89e3\u3002\u5904\u7406\u5f02\u5e38\u7684\u65b9\u5f0f\u5f88\u597d\u5730\u8bf4\u660e\u4e86\u539f\u4f5c\u8005\u5728\u7f16\u5199\u65b9\u6cd5\u65f6\u7684\u610f\u56fe\u3002<br \/>\n<strong>\u6e05\u5355 8. \u826f\u597d\u4e60\u60ef\uff1a\u5904\u7406\u5f02\u5e38<\/strong><\/p>\n<table style=\"width: 616px; height: 1033px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"616\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\r\n\/**\r\n * This is the exception thrown if the day of the week is invalid.\r\n * @author nagood\r\n *\r\n *\/\r\nclass InvalidDayOfWeekException extends Exception { }\r\n\r\nclass InvalidDayFormatException extends Exception { }\r\n\r\n\/**\r\n * Gets the name of the day given the day in the week. Will\r\n * return an error if the value supplied is out of range.\r\n *\r\n * @param $day\r\n * @return unknown_type\r\n *\/\r\nfunction convertDayOfWeekToName($day)\r\n{\r\n    if (! is_numeric($day)) {\r\n        throw new InvalidDayFormatException('The value \\'' . $day . '\\' is an ' .\r\n            'invalid format for a day of week.');\r\n    }\r\n\r\n    if (($day &gt; 6) || ($day &lt; 0)) {\r\n        throw new InvalidDayOfWeekException('The day number \\'' . $day . '\\' is an ' .\r\n            'invalid day of the week. Expecting 0-6.');\r\n    }\r\n\r\n    $dayNames = array(\r\n    \"Sunday\",\r\n    \"Monday\",\r\n    \"Tuesday\",\r\n    \"Wednesday\",\r\n    \"Thursday\",\r\n    \"Friday\",\r\n    \"Saturday\");\r\n    return $dayNames[$day];\r\n}\r\n\r\necho(\"The name of the 0 day is:  \" . convertDayOfWeekToName(0) . \"\\n\");\r\n\r\ntry {\r\n    echo(\"The name of the 10 day is:  \" . convertDayOfWeekToName(10) . \"\\n\");\r\n} catch (InvalidDayOfWeekException $e) {\r\n    echo (\"Encountered error while trying to convert value:  \" . $e-&gt;getMessage() . \"\\n\");\r\n}\r\n\r\ntry {\r\n    echo(\"The name of the 'orange' day is:  \" . convertDayOfWeekToName('orange') . \"\\n\");\r\n} catch (InvalidDayFormatException $e) {\r\n    echo (\"Encountered error while trying to convert value:  \" . $e-&gt;getMessage() . \"\\n\");\r\n}\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u867d\u7136\u68c0\u67e5\u53c2\u6570\u662f\u4e00\u79cd\u786e\u8ba4 \u2014 \u5982\u679c\u60a8\u8981\u6c42\u53c2\u6570\u5904\u4e8e\u67d0\u79cd\u72b6\u6001\uff0c\u8fd9\u5c06\u5bf9\u4f7f\u7528\u65b9\u6cd5\u7684\u4eba\u5f88\u6709\u5e2e\u52a9 \u2014 \u4f46\u662f\u60a8\u5e94\u8be5\u68c0\u67e5\u5b83\u4eec\u5e76\u629b\u51fa\u6709\u610f\u4e49\u7684\u5f02\u5e38\uff1a<\/p>\n<ul>\n<li>\u5904\u7406\u5f02\u5e38\u8981\u5c3d\u91cf\u4e0e\u51fa\u73b0\u7684\u95ee\u9898\u7d27\u5bc6\u76f8\u5173\u3002<\/li>\n<li>\u4e13\u95e8\u5904\u7406\u6bcf\u4e2a\u5f02\u5e38\u3002<\/li>\n<\/ul>\n<tbody><\/tbody>\n<p><span class=\"atitle\">\u5207\u5fcc\u4f7f\u7528\u590d\u5236\u7c98\u8d34<\/span><\/p>\n<p>\u60a8\u53ef\u4ee5\u4ece\u5176\u4ed6\u5730\u65b9\u5c06\u4ee3\u7801\u590d\u5236\u7c98\u8d34\u5230\u81ea\u5df1\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u4f46\u8fd9\u6837\u505a\u6709\u5229\u4e5f\u6709\u5f0a\u3002\u597d\u7684\u4e00\u9762\u662f\uff0c\u4ece\u4e00\u4e2a\u793a\u4f8b\u6216\u6a21\u677f\u4e2d\u590d\u5236\u4ee3\u7801\u80fd\u591f\u907f\u514d\u5f88\u591a\u9519\u8bef\u3002\u4e0d\u597d\u7684\u4e00\u9762\u662f\uff0c\u8fd9\u5bb9\u6613\u5e26\u6765\u5927\u91cf\u7684\u7c7b\u4f3c\u7f16\u7a0b\u65b9\u5f0f\u3002<\/p>\n<p>\u4e00\u5b9a\u8981\u6ce8\u610f\uff0c\u4e0d\u8981\u5c06\u4ee3\u7801\u4ece\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u90e8\u5206\u590d\u5236\u7c98\u8d34\u5230\u53e6\u4e00\u90e8\u5206\u3002\u5982\u679c\u60a8\u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\uff0c\u8bf7\u505c\u6b62\u8fd9\u4e2a\u4e0d\u826f\u7684\u4e60\u60ef\uff0c\u7136\u540e\u8003\u8651\u5c06\u8fd9\u6bb5\u4ee3\u7801\u91cd\u5199\u4e3a\u53ef\u91cd\u7528\u7684\u3002\u4e00\u822c\u800c\u8a00\uff0c\u5c06\u4ee3\u7801\u653e\u7f6e\u5230\u4e00\u4e2a\u5730\u65b9\u4fbf\u4e8e\u65e5\u540e\u7684\u7ef4\u62a4\uff0c\u56e0\u4e3a\u8fd9\u6837\u53ea\u9700\u5728\u4e00\u4e2a\u5730\u65b9\u66f4\u6539\u4ee3\u7801\u3002<\/p>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u4e0d\u826f\u4e60\u60ef\uff1a\u7c7b\u4f3c\u7684\u4ee3\u7801\u6bb5<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 9 \u7ed9\u51fa\u4e86\u51e0\u4e2a\u51e0\u4e4e\u4e00\u6837\u7684\u65b9\u6cd5\uff0c\u53ea\u662f\u5176\u4e2d\u7684\u503c\u4e0d\u540c\u800c\u5df2\u3002\u6709\u4e00\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u627e\u5230\u590d\u5236\u7c98\u8d34\u8fc7\u6765\u7684\u4ee3\u7801\uff08\u53c2\u89c1 <a href=\"http:\/\/www.lmyoaoa.com\/inn\/wp-admin\/#resources\"><span style=\"color: #5c81a7;\">\u53c2\u8003\u8d44\u6599<\/span><\/a>\uff09\u3002<br \/>\n<a name=\"listing9\"><strong>\u6e05\u5355 9. \u4e0d\u826f\u4e60\u60ef\uff1a\u7c7b\u4f3c\u7684\u4ee3\u7801\u6bb5<\/strong><\/a><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n\/**\r\n * Counts the number of messages found in the array of\r\n * ResultMessage with the getSeverity() value of \"Error\"\r\n *\r\n * @param $messages An array of ResultMessage\r\n * @return unknown_type\r\n *\/\r\nfunction countErrors($messages)\r\n{\r\n    $matchingCount = 0;\r\n    foreach($messages as $m) {\r\n        if ($m-&gt;getSeverity() == \"Error\") {\r\n            $matchingCount++;\r\n        }\r\n    }\r\n    return $matchingCount;\r\n}\r\n\r\n\/**\r\n * Counts the number of messages found in the array of\r\n * ResultMessage with the getSeverity() value of \"Warning\"\r\n *\r\n * @param $messages An array of ResultMessage\r\n * @return unknown_type\r\n *\/\r\nfunction countWarnings($messages)\r\n{\r\n    $matchingCount = 0;\r\n    foreach($messages as $m) {\r\n        if ($m-&gt;getSeverity() == \"Warning\") {\r\n            $matchingCount++;\r\n        }\r\n    }\r\n    return $matchingCount;\r\n}\r\n\r\n\/**\r\n * Counts the number of messages found in the array of\r\n * ResultMessage with the getSeverity() value of \"Information\"\r\n *\r\n * @param $messages An array of ResultMessage\r\n * @return unknown_type\r\n *\/\r\nfunction countInformation($messages)\r\n{\r\n    $matchingCount = 0;\r\n    foreach($messages as $m) {\r\n        if ($m-&gt;getSeverity() == \"Information\") {\r\n            $matchingCount++;\r\n        }\r\n    }\r\n    return $matchingCount;\r\n}\r\n\r\n$messages = array(new ResultMessage(\"Error\", \"This is an error!\"),\r\n    new ResultMessage(\"Warning\", \"This is a warning!\"),\r\n    new ResultMessage(\"Error\", \"This is another error!\"));\r\n\r\n$errs = countErrors($messages);\r\n\r\necho(\"There are \" . $errs . \" errors in the result.\\n\");\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"smalltitle\"><strong><span style=\"font-size: small; font-family: Arial;\">\u826f\u597d\u4e60\u60ef\uff1a\u5e26\u53c2\u6570\u7684\u53ef\u91cd\u7528\u51fd\u6570<\/span><\/strong><\/span><\/p>\n<p>\u6e05\u5355 10 \u5c55\u793a\u4e86\u4fee\u6539\u540e\u7684\u4ee3\u7801\uff0c\u5b83\u5c06\u590d\u5236\u7684\u4ee3\u7801\u653e\u5230\u4e00\u4e2a\u65b9\u6cd5\u4e2d\u3002\u53e6\u4e00\u4e2a\u65b9\u6cd5\u4e5f\u8fdb\u884c\u4e86\u66f4\u6539\uff0c\u5b83\u73b0\u5728\u5c06\u4efb\u52a1\u59d4\u6258\u7ed9\u65b0\u7684\u65b9\u6cd5\u3002\u6784\u5efa\u901a\u7528\u7684\u65b9\u6cd5\u9700\u8981\u82b1\u65f6\u95f4\u8bbe\u8ba1\uff0c\u5e76\u4e14\u8fd9\u6837\u505a\u4f7f\u60a8\u80fd\u505c\u4e0b\u6765\u601d\u8003\uff0c\u800c\u4e0d\u662f\u672c\u80fd\u5730\u4f7f\u7528\u590d\u5236\u7c98\u8d34\u3002\u4f46\u6709\u5fc5\u8981\u8fdb\u884c\u66f4\u6539\u65f6\uff0c\u5bf9\u901a\u7528\u7684\u65b9\u6cd5\u6295\u5165\u7684\u65f6\u95f4\u5c06\u5f97\u5230\u56de\u62a5\u3002<br \/>\n<strong>\u6e05\u5355 10. \u826f\u597d\u4e60\u60ef\uff1a\u5e26\u53c2\u6570\u7684\u53ef\u91cd\u7528\u51fd\u6570<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"code-outline\">\n<pre class=\"displaycode\">&lt;?php\r\n    \/*\r\n     * Counts the messages with the given severity in the array\r\n     * of messages.\r\n     *\r\n     * @param $messages An array of ResultMessage\r\n     * @return int Count of messages matching $withSeverity\r\n     *\/\r\n    function countMessages($messages, $withSeverity)\r\n    {\r\n        $matchingCount = 0;\r\n        foreach($messages as $m) {\r\n            if ($m-&gt;getSeverity() == $withSeverity) {\r\n                $matchingCount++;\r\n            }\r\n        }\r\n        return $matchingCount;\r\n    }\r\n\r\n    \/**\r\n     * Counts the number of messages found in the array of\r\n     * ResultMessage with the getSeverity() value of \"Error\"\r\n     *\r\n     * @param $messages An array of ResultMessage\r\n     * @return unknown_type\r\n     *\/\r\n    function countErrors($messages)\r\n    {\r\n        return countMessages($messages, \"Errors\");\r\n    }\r\n\r\n    \/**\r\n     * Counts the number of messages found in the array of\r\n     * ResultMessage with the getSeverity() value of \"Warning\"\r\n     *\r\n     * @param $messages An array of ResultMessage\r\n     * @return unknown_type\r\n     *\/\r\n    function countWarnings($messages)\r\n    {\r\n        return countMessages($messages, \"Warning\");\r\n    }\r\n\r\n    \/**\r\n     * Counts the number of messages found in the array of\r\n     * ResultMessage with the getSeverity() value of \"Warning\"\r\n     *\r\n     * @param $messages An array of ResultMessage\r\n     * @return unknown_type\r\n     *\/\r\n    function countInformation($messages)\r\n    {\r\n        return countMessages($messages, \"Information\");\r\n    }\r\n\r\n    $messages = array(new ResultMessage(\"Error\", \"This is an error!\"),\r\n        new ResultMessage(\"Warning\", \"This is a warning!\"),\r\n        new ResultMessage(\"Error\", \"This is another error!\"));\r\n\r\n    $errs = countErrors($messages);\r\n\r\n    echo(\"There are \" . $errs . \" errors in the result.\\n\");\r\n\r\n?&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"atitle\">\u7ed3\u675f\u8bed<\/span><\/p>\n<p>\u5982\u679c\u60a8\u5728\u7f16\u5199 PHP \u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d\u517b\u6210\u672c\u6587\u8ba8\u8bba\u7684\u826f\u597d\u4e60\u60ef\uff0c\u60a8\u5c06\u80fd\u591f\u6784\u5efa\u6613\u8bfb\u3001\u6613\u7406\u89e3\u3001\u6613\u7ef4\u62a4\u7684\u4ee3\u7801\u3002\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u6784\u5efa\u7684\u6613\u7ef4\u62a4\u4ee3\u7801\u5c06\u964d\u4f4e\u8c03\u8bd5\u3001\u4fee\u590d\u548c\u6269\u5c55\u4ee3\u7801\u6240\u9762\u4e34\u7684\u98ce\u9669\u3002<\/p>\n<p>\u4f7f\u7528\u826f\u597d\u7684\u540d\u79f0\u548c\u66f4\u77ed\u7684\u65b9\u6cd5\u80fd\u591f\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002\u6ce8\u91ca\u4ee3\u7801\u7684\u76ee\u7684\u6709\u5229\u4e8e\u4ee3\u7801\u7406\u89e3\u548c\u6269\u5c55\u3002\u9002\u5f53\u5730\u5904\u7406\u9519\u8bef\u4f1a\u4f7f\u4ee3\u7801\u66f4\u52a0\u5065\u58ee\u3002\u6700\u540e\uff0c\u505c\u6b62\u4f7f\u7528\u590d\u5236\u7c98\u8d34\uff0c\u4fdd\u6301\u4ee3\u7801\u5e72\u51c0\uff0c\u63d0\u9ad8\u53ef\u91cd\u7528\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u7684\uff0c\u65b9\u4fbf\u6211\u81ea\u5df1\u770b\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7 \u3000\u3000\u6839\u636e\u5177\u4f53\u7684\u60c5\u51b5\uff0c\u4e00\u822c\u7684\u5f00\u53d1\u4eba\u5458\u5f80\u5f80\u6bd4\u4f18\u79c0\u7684\u5f00\u53d1\u4eba\u5458\u7684\u6548\u7387\u4f4e 10%~20% [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[57,56],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-technology","tag-57","tag-56"],"_links":{"self":[{"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":0,"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lmyoaoa.com\/inn\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}