{"id":31929,"date":"2024-11-25T16:51:21","date_gmt":"2024-11-25T08:51:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31929\/"},"modified":"2024-11-25T16:51:21","modified_gmt":"2024-11-25T08:51:21","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%ad%e5%af%8c%e6%96%87%e6%9c%ac%e8%bd%ac%e6%96%87%e6%9c%ac%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31929\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5bcc\u6587\u672c\u8f6c\u6587\u672c\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u5bcc\u6587\u672c\u8f6c\u6587\u672c\u5b9e\u4f8b\u8be6\u89e3\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f-\u5bcc\u6587\u672c\u8f6c\u6587\u672c<\/strong><\/p>\n<p>\u6700\u8fd1\u5c0f\u7a0b\u5e8f\u8fd9\u4e48\u706b\uff0c\u6211\u4e5f\u6765\u641e\u641e\u3002\u53d1\u73b0\u4e86\u4e00\u4e2a\u6076\u5fc3\u7684\u95ee\u9898\u3002\u5c0f\u7a0b\u5e8f\u6ca1\u6709\u7ec4\u4ef6\u80fd\u652f\u6301\u5bcc\u6587\u672c\u5185\u5bb9\u7684\uff0c\u6539\u63a5\u53e3\u53c8\u4e0d\u592a\u5408\u9002\uff0c\u4e8e\u662f\u6709\u4e86\u8fd9\u95ee\uff0c\u6ca1\u6280\u672f\u542b\u91cf\u7eaf\u7cb9\u8bb0\u5f55<\/p>\n<p>\u9996\u5148\u6211\u4eec\u770b\u773c\u6ca1\u6709\u88ab\u683c\u5f0f\u7684\u5bcc\u6587\u672c\u663e\u793a\uff1a<\/p>\n<p>*.wxml\u5185\u4ee3\u7801\u3002content\u662f\u5bcc\u6587\u672c\u5185\u5bb9<\/p>\n<\/p>\n<pre>\n&nbsp;&lt;view&gt;\n&nbsp;&nbsp;&nbsp;&lt;text&gt;{{content}}&lt;\/text&gt;\n&nbsp;&nbsp;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u663e\u793a\u7ed3\u679c\uff1a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/009\/eaff292df68b041915e73b4736db5067-0.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5bcc\u6587\u672c\u8f6c\u6587\u672c\u7684\u5b9e\u73b0\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5bcc\u6587\u672c\u8f6c\u6587\u672c\u7684\u5b9e\u73b0\u63d2\u56fe\" \/><\/p>\n<p>\u7531\u4ee5\u4e0a\u56fe\u7247\u770b\u5230\uff0c\u5c0f\u7a0b\u5e8f\u65e0\u6cd5\u89e3\u6790html\u6587\u4ef6<\/p>\n<p><strong>\u6211\u4eec\u9700\u8981\u5904\u7406html\u5bcc\u6587\u672c\u5185\u5bb9\uff0c\u8ba9\u5176\u663e\u793a\u597d\u770b\u70b9<\/strong><\/p>\n<p>\u4e0b\u9762\u76f4\u63a5\u4e0a\u4ee3\u7801\u4e86\uff0c\u4e3b\u8981\u529f\u80fd\u5c31\u662f\u5229\u7528js\u7684replace \u5bf9\u5bcc\u6587\u672c\u7ecf\u884c\u5904\u7406\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u4e00\u4e0b\u3002\u4e00\u8d77\u4f18\u5316\uff0c\u65b9\u4fbf\u5bf9\u5bcc\u6587\u672c\u66f4\u597d\u7684\u5904\u7406\u3002<\/p>\n<\/p>\n<pre>convertHtmlToText:&nbsp;function&nbsp;convertHtmlToText(inputText)&nbsp;{\n&nbsp;&nbsp;var&nbsp;returnText&nbsp;=&nbsp;\"\"&nbsp;+&nbsp;inputText;\n&nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/ig,&nbsp;'\r\n');\n&nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/ig,&nbsp;'\r\n');\n&nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<li>\/ig,&nbsp;&#8216;&nbsp;*&nbsp;&#8216;); &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/ig,&nbsp;&#8216; &#8216;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;BR&nbsp;tags&nbsp;and&nbsp;replace&nbsp;them&nbsp;with&nbsp;line&nbsp;break &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/<br \/>\/gi,&nbsp;&#8221; &#8220;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;P&nbsp;and&nbsp;A&nbsp;tags&nbsp;but&nbsp;preserve&nbsp;what&#8217;s&nbsp;inside&nbsp;of&nbsp;them &nbsp;&nbsp;returnText=returnText.replace(\/ \/gi,&nbsp;&#8221; &#8220;); &nbsp;&nbsp;returnText=returnText.replace(\/ (.*?)\/gi,&nbsp;&#8221;&nbsp;$2&nbsp;($1)&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;all&nbsp;inside&nbsp;SCRIPT&nbsp;and&nbsp;STYLE&nbsp;tags &nbsp;&nbsp;returnText=returnText.replace(\/ [wW]{1,}(.*?)[wW]{1,}\/gi,&nbsp;&#8220;&#8221;); &nbsp;&nbsp;returnText=returnText.replace(\/ [wW]{1,}(.*?)[wW]{1,}\/gi,&nbsp;&#8220;&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;all&nbsp;else &nbsp;&nbsp;returnText=returnText.replace(\/\/g,&nbsp;&#8220;&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;get&nbsp;rid&nbsp;of&nbsp;more&nbsp;than&nbsp;2&nbsp;multiple&nbsp;line&nbsp;breaks: &nbsp;&nbsp;returnText=returnText.replace(\/(?:(?: | | )s*){2,}\/gim,&nbsp;&#8221; &#8220;); &nbsp;&nbsp;\/\/&#8211;&nbsp;get&nbsp;rid&nbsp;of&nbsp;more&nbsp;than&nbsp;2&nbsp;spaces: &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/&nbsp;+(?=&nbsp;)\/g,&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;get&nbsp;rid&nbsp;of&nbsp;html-encoded&nbsp;characters: &nbsp;&nbsp;returnText=returnText.replace(\/&nbsp;\/gi,&#8221;&nbsp;&#8220;); &nbsp;&nbsp;returnText=returnText.replace(\/&amp;\/gi,&#8221;&amp;&#8221;); &nbsp;&nbsp;returnText=returnText.replace(\/&#8221;\/gi,'&#8221;&#8216;); &nbsp;&nbsp;returnText=returnText.replace(\/,&#8217;\/gi,&#8217;&gt;&#8217;); &nbsp;&nbsp;return&nbsp;returnText; }\n<\/p>\n<p>\u5c06\u4e0a\u9762\u4ee3\u7801\u653e\u5165\u4efb\u610f\u9002\u5408\u7684\u5c0f\u7a0b\u5e8fjs\u6587\u4ef6\u4e2d\uff0c \u7136\u540e\u5728\u9700\u8981\u5904\u7406\u6570\u636e\u7684js\u6587\u4ef6\u91cc\uff0c\u5f15\u5165\u6587\u4ef6\uff0c\u4e0b\u9762\u7ed9\u51fa\u653e\u5165app.js\u6587\u4ef6\u4e2d\u7684\u8c03\u7528\u793a<\/p>\n<p>\u4f8b\uff1a<\/p>\n<\/p>\n<pre>var&nbsp;app&nbsp;=&nbsp;getApp()\/\/\u83b7\u53d6app\u5c0f\u7a0b\u5e8f\u5b9e\u4f8b\n&nbsp;onLoad:&nbsp;function&nbsp;(options)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;wx.request({\n&nbsp;&nbsp;&nbsp;url:&nbsp;'http:\/\/example.com\/api'&nbsp;+&nbsp;options.id+'.json',\n&nbsp;&nbsp;&nbsp;headers:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;'Content-Type':&nbsp;'application\/json'\n&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;success:&nbsp;function&nbsp;(res)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;res.data.content&nbsp;=&nbsp;app.convertHtmlToText(res.data.content&nbsp;)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;art:&nbsp;res.data.content\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(res.data)\n&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;})\n\uff5d<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u7f16\u8bd1\u5237\u65b0\u4e0b\uff0c\u53ef\u4ee5\u770b\u5230\u7ed3\u679c\u4e86\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/009\/7bf10e1753d0fbd72ed9eb9abc7efdc1-1.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5bcc\u6587\u672c\u8f6c\u6587\u672c\u7684\u5b9e\u73b0\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5bcc\u6587\u672c\u8f6c\u6587\u672c\u7684\u5b9e\u73b0\u63d2\u56fe1\" \/><\/p>\n<p>\u8fd9\u91cc\u53ef\u4ee5\u7ee7\u7eed\u8c03\u6574\u4e0bcss\uff0c\u4f7f\u663e\u793a\u5f97\u66f4\u597d\u770b\u70b9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff0c\u66f4\u591a\u76f8\u5173\u5185\u5bb9\u8bf7\u5173\u6ce8PHP\u4e2d\u6587\u7f51\uff01<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<p><\/p>\n<p><\/p>\n<p><\/p>\n<\/p>\n<p><span><\/span><\/p>\n<\/li>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5bcc\u6587\u672c\u8f6c\u6587\u672c\u7684\u5b9e\u73b0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u5bcc\u6587\u672c\u8f6c\u6587\u672c\u5b9e\u4f8b\u8be6\u89e3\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b \u5fae\u4fe1\u5c0f\u7a0b\u5e8f-\u5bcc\u6587\u672c\u8f6c\u6587\u672c \u6700\u8fd1\u5c0f\u7a0b\u5e8f\u8fd9\u4e48\u706b\uff0c\u6211\u4e5f\u6765\u641e\u641e\u3002\u53d1\u73b0\u4e86\u4e00\u4e2a\u6076\u5fc3\u7684\u95ee\u9898\u3002\u5c0f\u7a0b\u5e8f\u6ca1\u6709\u7ec4\u4ef6\u80fd\u652f\u6301\u5bcc\u6587\u672c\u5185\u5bb9\u7684\uff0c\u6539\u63a5\u53e3\u53c8\u4e0d\u592a\u5408\u9002\uff0c\u4e8e\u662f\u6709\u4e86\u8fd9\u95ee\uff0c\u6ca1\u6280\u672f\u542b\u91cf\u7eaf\u7cb9\u8bb0\u5f55 \u9996\u5148\u6211\u4eec\u770b\u773c\u6ca1\u6709\u88ab\u683c\u5f0f\u7684\u5bcc\u6587\u672c\u663e\u793a\uff1a *.wxml\u5185\u4ee3\u7801\u3002content\u662f\u5bcc\u6587\u672c\u5185\u5bb9 &nbsp;&lt;view&gt; &nbsp;&nbsp;&nbsp;&lt;text&gt;{{content}}&lt;\/text&gt; &nbsp;&nbsp;&lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 \u663e\u793a\u7ed3\u679c\uff1a \u7531\u4ee5\u4e0a\u56fe\u7247\u770b\u5230\uff0c\u5c0f\u7a0b\u5e8f\u65e0\u6cd5\u89e3\u6790html\u6587\u4ef6 \u6211\u4eec\u9700\u8981\u5904\u7406html\u5bcc\u6587\u672c\u5185\u5bb9\uff0c\u8ba9\u5176\u663e\u793a\u597d\u770b\u70b9 \u4e0b\u9762\u76f4\u63a5\u4e0a\u4ee3\u7801\u4e86\uff0c\u4e3b\u8981\u529f\u80fd\u5c31\u662f\u5229\u7528js\u7684replace \u5bf9\u5bcc\u6587\u672c\u7ecf\u884c\u5904\u7406\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u4e00\u4e0b\u3002\u4e00\u8d77\u4f18\u5316\uff0c\u65b9\u4fbf\u5bf9\u5bcc\u6587\u672c\u66f4\u597d\u7684\u5904\u7406\u3002 convertHtmlToText:&nbsp;function&nbsp;convertHtmlToText(inputText)&nbsp;{ &nbsp;&nbsp;var&nbsp;returnText&nbsp;=&nbsp;&#8220;&#8221;&nbsp;+&nbsp;inputText; &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/ig,&nbsp;&#8216; &#8216;); &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/ig,&nbsp;&#8216; &#8216;); &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/ \u767b\u5f55\u540e\u590d\u5236 \/ig,&nbsp;&#8216;&nbsp;*&nbsp;&#8216;); &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/ig,&nbsp;&#8216; &#8216;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;BR&nbsp;tags&nbsp;and&nbsp;replace&nbsp;them&nbsp;with&nbsp;line&nbsp;break &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/\/gi,&nbsp;&#8221; &#8220;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;P&nbsp;and&nbsp;A&nbsp;tags&nbsp;but&nbsp;preserve&nbsp;what&#8217;s&nbsp;inside&nbsp;of&nbsp;them &nbsp;&nbsp;returnText=returnText.replace(\/ \/gi,&nbsp;&#8221; &#8220;); &nbsp;&nbsp;returnText=returnText.replace(\/ (.*?)\/gi,&nbsp;&#8221;&nbsp;$2&nbsp;($1)&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;all&nbsp;inside&nbsp;SCRIPT&nbsp;and&nbsp;STYLE&nbsp;tags &nbsp;&nbsp;returnText=returnText.replace(\/ [wW]{1,}(.*?)[wW]{1,}\/gi,&nbsp;&#8220;&#8221;); &nbsp;&nbsp;returnText=returnText.replace(\/ [wW]{1,}(.*?)[wW]{1,}\/gi,&nbsp;&#8220;&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;remove&nbsp;all&nbsp;else &nbsp;&nbsp;returnText=returnText.replace(\/\/g,&nbsp;&#8220;&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;get&nbsp;rid&nbsp;of&nbsp;more&nbsp;than&nbsp;2&nbsp;multiple&nbsp;line&nbsp;breaks: &nbsp;&nbsp;returnText=returnText.replace(\/(?:(?: | | )s*){2,}\/gim,&nbsp;&#8221; &#8220;); &nbsp;&nbsp;\/\/&#8211;&nbsp;get&nbsp;rid&nbsp;of&nbsp;more&nbsp;than&nbsp;2&nbsp;spaces: &nbsp;&nbsp;returnText&nbsp;=&nbsp;returnText.replace(\/&nbsp;+(?=&nbsp;)\/g,&#8221;); &nbsp;&nbsp;\/\/&#8211;&nbsp;get&nbsp;rid&nbsp;of&nbsp;html-encoded&nbsp;characters: &nbsp;&nbsp;returnText=returnText.replace(\/&nbsp;\/gi,&#8221;&nbsp;&#8220;); &nbsp;&nbsp;returnText=returnText.replace(\/&amp;\/gi,&#8221;&amp;&#8221;); &nbsp;&nbsp;returnText=returnText.replace(\/&#8221;\/gi,&#8217;&#8221;&#8216;); &nbsp;&nbsp;returnText=returnText.replace(\/,&#8217;\/gi,&#8217;&gt;&#8217;); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-31929","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31929"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31929\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}