{"id":1232,"date":"2010-05-02T22:04:28","date_gmt":"2010-05-02T14:04:28","guid":{"rendered":"http:\/\/nan.im\/blog\/?p=1232"},"modified":"2010-05-02T22:04:28","modified_gmt":"2010-05-02T14:04:28","slug":"%e5%9c%a8-drupal-%e4%b8%ad%e4%bd%bf%e7%94%a8-check_plain-%e5%92%8c-t-%e6%9d%a5%e5%ae%89%e5%85%a8%e8%be%93%e5%87%ba%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"http:\/\/nan.im\/blog\/1232","title":{"rendered":"\u3010Drupal\u3011\u4e2d\u4f7f\u7528 check_plain \u548c t \u51fd\u6570\u6765\u5b89\u5168\u5904\u7406\u5b57\u7b26"},"content":{"rendered":"<p>\u4ece\u4e8b Drupal \u6a21\u5757\u5f00\u53d1\u7279\u522b\u662f\u4e3b\u9898\u5f00\u53d1\u4e2d\u4f1a\u7ecf\u5e38\u9700\u8981\u8f93\u51fa\u6216\u8005\u8c03\u7528\u4e00\u4e9b\u6587\u672c\u6216\u5b57\u7b26\uff0c\u4f46\u5982\u679c\u662f\u4e0d\u4fe1\u4efb\u6765\u6e90\u7684\u5b57\u4e32\u5982\u5f00\u653e\u7ed9\u4efb\u610f\u7528\u6237\u4f7f\u7528\u7684\u4e00\u4e9b\u8f93\u5165\u7b49\u7b49\uff0c\u8fd9\u7c7b\u4e0d\u4fe1\u4efb\u7684\u5b57\u4e32\u5728\u8f93\u51fa\u6216\u4f7f\u7528\u65f6\u8bf7\u4e0d\u8981\u5927\u610f\uff0c\u672a\u7ecf\u8fc7\u6ee4\u7684\u4e0d\u4fe1\u4efb\u5b57\u7b26\u5c06\u7ed9\u4f60\u7684\u9879\u76ee\u5e26\u6765\u5de8\u5927\u7684\u9690\u60a3\uff0c\u597d\u5728 Drupal \u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a check_plain \u53ca\u7528\u4e8e\u7ffb\u8bd1\u7684 t \u51fd\u6570\u7528\u6765\u4f18\u96c5\u7684\u5904\u7406\u8fd9\u7c7b\u95ee\u9898\u3002<!--more--><\/p>\n<p>\u5173\u4e8e\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5\u53ef\u4ee5\u53c2\u8003 api.drupal.org \u7684\u5b98\u65b9\u4ecb\u7ecd\uff1a<\/p>\n<p>t()\uff1ahttp:\/\/api.drupal.org\/api\/function\/t\/6<\/p>\n<p>check_plain()\uff1ahttp:\/\/api.drupal.org\/api\/function\/check_plain\/6<\/p>\n<p>\u5f53\u5f00\u53d1\u8005\u5bf9\u4e8e\u5373\u5c06\u4f7f\u7528\u6216\u8f93\u51fa\u5b57\u4e32\u4e0d\u4fe1\u4efb\u7684\u65f6\u5019\u53ef\u4ee5\u4f7f\u7528 check_plain \u6765\u5b89\u5168\u4f18\u96c5\u7684\u8fc7\u6ee4\u6389\u4e0d\u5b89\u5168\u4ee3\u7801\uff0c\u4e0b\u9762\u662f\u4e00\u4e9b\u7b80\u5355\u7684\u793a\u4f8b\u53ca\u8bf4\u660e\uff0c\u5176\u4e2d drupal_set_message \u662f\u7528\u4e8e\u5411 Drupal \u524d\u7aef\u8fd4\u56de\u4e00\u6bb5\u4fe1\u606f\u7684\u51fd\u6570\uff0c\u6211\u8fd9\u91cc\u5047\u5b9a $tText \u4e3a\u6765\u81ea\u4e0d\u4fe1\u4efb\u6765\u6e90\u7684\u4e00\u6bb5\u5b57\u4e32\uff0c\u800c\u4f7f\u7528 t \u51fd\u6570\u7684\u539f\u56e0\u662f\u6211\u4eec\u9700\u8981\u8f93\u51fa\u7684\u8fd9\u6bb5\u5b57\u4e32\u53ef\u4ee5\u88ab\u7ffb\u8bd1\uff1a<\/p>\n<p>1\u3001\u9996\u5148\u662f\u4e00\u4e9b\u672a\u91c7\u53d6\u4efb\u4f55\u63aa\u65bd\u7684\u4fe1\u606f\u8c03\u7528\u53ca\u8f93\u51fa\uff1a<\/p>\n<p>echo t(&#8216;Some Text For Testing&#8217;);      \/\/\u672a\u5305\u542b\u4e0d\u4fe1\u4efb\u53d8\u91cf\u65f6\u8be5\u65b9\u6cd5\u5b89\u5168\uff1b<\/p>\n<p>echo t(&#8220;Some $testText For Testing&#8221;);      \/\/\u4e00\u65e6\u5305\u542b\u4e0d\u4fe1\u4efb\u5185\u5bb9\u5219\u4e0d\u5b89\u5168\uff1b<\/p>\n<p>2\u3001\u7136\u540e\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 check_plain \u6765\u5904\u7406\u4e0d\u4fe1\u4efb\u7684\u5b57\u4e32\u5982\u4e0b\uff1a<\/p>\n<p>echo check_plain($testText);<\/p>\n<p>echo t(&#8216;Some&#8217;),check_plain($testText),t(&#8216;For Testing&#8217;);      \/\/\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u518d t \u4e00\u6b21\u4f46\u4e8b\u60c5\u5c31\u53d8\u7684\u590d\u6742\u4e86\uff1b<\/p>\n<p>3\u3001\u4f46\u5982\u6b64\u8f93\u51fa\u7684\u76f4\u63a5\u7ed3\u679c\u4fbf\u662f\u6765\u81ea\u7528\u6237\u7684\u5b57\u4e32 testText \u65e0\u6cd5\u88ab\u7ffb\u8bd1\uff0c\u597d\u5728 Drupal \u7684 t \u51fd\u6570\u4f7f\u7528 @ \u5360\u4f4d\u7b26\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u53e6\u5916\u4e00\u79cd\u65b9\u5f0f\u6765\u786e\u4fdd\u5b89\u5168\uff1a<\/p>\n<p>echo t(&#8216;Some @testText For Testing&#8217;, array(&#8216;@testText&#8217; => $testText));      \/\/\u4f7f\u7528\u8fd9\u79cd\u683c\u5f0f\u5c06\u975e\u5e38\u5229\u4e8e\u7ffb\u8bd1\u4eba\u5458\u64cd\u4f5c\uff1b<\/p>\n<p>\u5f53\u7136\u8fd9\u91cc\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u4e00\u4e9b\u5360\u4f4d\u7b26\u4f8b\u5982 % \u548c ! \u7b49\u7b49\u4ee5\u5b9e\u73b0\u4e0d\u540c\u7684\u9700\u6c42\u5982\u6dfb\u52a0 html \u4ee3\u7801\u6216\u8005\u8df3\u8fc7 check_plain \u7b49\u7b49\uff0c\u5177\u4f53\u53ef\u53c2\u8003 api.drupal.org \u4e0a\u5173\u4e8e t \u51fd\u6570\u7684\u4e00\u4e9b\u7528\u6cd5\u793a\u4f8b\uff0c\u7531\u4e8e Drupal \u91cc\u5f88\u591a\u51fd\u6570\u90fd\u5df2\u7ecf\u5185\u7f6e\u4e86 check_plain \u64cd\u4f5c\u5982\u5e38\u7528\u7684 l \u51fd\u6570\u7b49\u7b49\u6240\u4ee5 ! \u5360\u4f4d\u7b26\u4e5f\u4f1a\u7ecf\u5e38\u88ab\u7528\u5230\uff0c\u5f53\u7136\u5982\u679c l \u51fd\u6570\u7684 html \u5c5e\u6027\u4e3a true \u65f6\u521b\u5efa\u94fe\u63a5\u8fd8\u662f\u9700\u8981\u8fc7\u6ee4\u7684\u3002\u6700\u540e\u9700\u8981\u8865\u5145\u7684\u662f\u524d\u9762\u6240\u505a\u7684\u52aa\u529b\u9700\u8981\u4e00\u4e2a\u524d\u63d0\u5c31\u662f\u4fe1\u4efb\u7684\u7ffb\u8bd1\uff0c\u5426\u5219\u5373\u4f7f\u4ee3\u7801\u4e0a\u65e0\u61c8\u53ef\u51fb\u5982\u679c\u5728\u7ffb\u8bd1\u4e0a\u51fa\u4e86\u95ee\u9898\u4e5f\u662f\u5f88\u8ba9\u4eba\u5934\u75bc\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u4e8b Drupal \u6a21\u5757\u5f00\u53d1\u7279\u522b\u662f\u4e3b\u9898\u5f00\u53d1\u4e2d\u4f1a\u7ecf\u5e38\u9700\u8981\u8f93\u51fa\u6216\u8005\u8c03\u7528\u4e00\u4e9b\u6587\u672c\u6216\u5b57\u7b26\uff0c\u4f46\u5982\u679c\u662f\u4e0d\u4fe1\u4efb\u6765\u6e90\u7684\u5b57\u4e32\u5982\u5f00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[20,31,120,76],"class_list":["post-1232","post","type-post","status-publish","format-standard","hentry","category-tech","tag-code","tag-drupal","tag-php","tag-theme"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts\/1232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/comments?post=1232"}],"version-history":[{"count":0,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts\/1232\/revisions"}],"wp:attachment":[{"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/media?parent=1232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/categories?post=1232"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nan.im\/blog\/wp-json\/wp\/v2\/tags?post=1232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}