{"id":1491,"date":"2017-11-19T16:04:43","date_gmt":"2017-11-19T07:04:43","guid":{"rendered":"http:\/\/www.dogrow.net\/php\/?p=1491"},"modified":"2018-09-27T01:24:22","modified_gmt":"2018-09-26T16:24:22","slug":"blog46","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/php\/blog46\/","title":{"rendered":"(46) preg_replace()\u306e\u4f7f\u3044\u65b9\u3044\u308d\u3044\u308d"},"content":{"rendered":"<p>\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u5099\u5fd8\u9332\u3002<\/p>\n<h3 class=\"my_h\">1) \u7279\u5b9a\u306eHTML\u30bf\u30b0\u3092\u9664\u53bb\u3059\u308b\u3002<\/h3>\n<p>&lt;img src=&#8221;xxxxx.gif&#8221;&gt;\u3092\u9664\u53bb\u3059\u308b\u3002<\/p>\n<pre class=\"brush: php; class-name: &#039;my_border_1px&#039;; title: ; notranslate\" title=\"\">\r\n$txt1 = 'AAAAA&lt;img src=&quot;xxxxx.gif&quot;&gt;BBBBB';\r\n$txt2 = preg_replace('\/&lt;\\s*img&#x5B;^&gt;]*&gt;\/i', '', $txt1);\r\necho $txt2;\r\n<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"my_pre\">\r\nAAAAABBBBB\r\n<\/pre>\n<p>\u6b63\u898f\u8868\u73fe\u300c\\&lt;\\s*img[^&gt;]*&gt;\/i\u300d\u306e\u610f\u5473\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n\u30fb<span class=\"my_fc_deeppink my_fw_bold\">&lt;<\/span> \u304b\u3089\u59cb\u307e\u308a\u3001<br \/>\n\u30fb<span class=\"my_fc_deeppink my_fw_bold\">\\s<\/span> \u7a7a\u767d\u6587\u5b57\u304c <span class=\"my_fc_deeppink my_fw_bold\">*<\/span>0\u500b\u4ee5\u4e0a\u7d9a\u304d\u3001<br \/>\n\u30fb<span class=\"my_fc_deeppink my_fw_bold\">img<\/span> \u304c\u3042\u308a\u3001<br \/>\n\u30fb<span class=\"my_fc_deeppink my_fw_bold\">[^&gt;]<\/span> &gt;\u3067\u306f\u306a\u3044\u6587\u5b57\u304c <span class=\"my_fc_deeppink my_fw_bold\">*<\/span>0\u500b\u4ee5\u4e0a\u7d9a\u304d\u3001<br \/>\n\u30fb<span class=\"my_fc_deeppink my_fw_bold\">&gt;<\/span> \u3067\u7d42\u308f\u308a\u3001<br \/>\n\u30fb<span class=\"my_fc_deeppink my_fw_bold\">i<\/span> \u5927\u6587\u5b57\u5c0f\u6587\u5b57\u3092\u533a\u5225\u305b\u305a\u3001<br \/>\n\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u691c\u51fa\u3057\u305f\u3089<span class=\"my_fc_deeppink my_fw_bold\">&#8221;<\/span> \u6587\u5b57\u7121\u3057\u306b\u7f6e\u63db\u3059\u308b\u3002<\/p>\n<p><span class=\"my_fc_red\">\u203b\u7e70\u308a\u8fd4\u3057\u6307\u5b9a\u306f\u4e0d\u8981\u3002\u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u4e2d\u3067\u30d2\u30c3\u30c8\u3059\u308b\u5168\u30d1\u30bf\u30fc\u30f3\u3092\u7f6e\u63db\u3057\u3066\u304f\u308c\u308b\u3002<\/span><\/p>\n<h3 class=\"my_h\">2) &lt;span style=&#8221;xxxxx&#8221;&gt; \uff5e &lt;\/span&gt; \u3092\u9664\u53bb\u3059\u308b\u3002<\/h3>\n<pre class=\"brush: php; class-name: &#039;my_border_1px&#039;; title: ; notranslate\" title=\"\">\r\n$txt1 = 'AAA&lt;span style=&quot;xxxxx&quot;&gt;BBB&lt;\/Span&gt;CCC';\r\n$txt2 = preg_replace(&quot;\/&lt;&#x5B;\\s]*span&#x5B;^&gt;]*&gt;&#x5B;^&lt;]*&lt;\\\/&#x5B;\\s]*span&#x5B;\\s]*&gt;\/i&quot;, '', $txt1);\r\necho $txt2;\r\n<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"my_pre\">\r\nAAACCC\r\n<\/pre>\n<p>\u3053\u308c\u306f\u4ee5\u4e0b\u306e\uff13\u3064\u306e\u30d1\u30fc\u30c4\u306b\u5206\u304b\u308c\u3066\u3044\u308b\u3002<br \/>\n<span class=\"my_fc_red\">&lt;[\\s]*span[^&gt;]*&gt;<\/span><span class=\"my_fc_green\">[^&lt;]*<\/span><span class=\"my_fc_blue\">&lt;\\\/[\\s]*span[\\s]*&gt;<\/span><\/p>\n<h3 class=\"my_h\">3) &apos; \u3092\u6587\u5b57\u53c2\u7167\uff08character references\uff09\u306b\u5909\u63db\u3059\u308b\u3002<\/h3>\n<p>htmlspecialchars()\u3092\u4f7f\u3063\u3066\u3057\u307e\u3048\u3070\u624b\u3063\u53d6\u308a\u65e9\u3044\u306e\u3060\u304c\u3001&gt; \u3068 &lt; \u306f\u5909\u3048\u305f\u304f\u306a\u3044\u5834\u5408\u3082\u3042\u308b\u3002<br \/>\n\u305d\u3093\u306a\u3068\u304d\u306f\u500b\u3005\u306e\u6587\u5b57\u306b\u3064\u3044\u3066\u5909\u63db\u3059\u308b\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$txt1 = &quot;AAA'B'CCC&quot;;\r\n$txt2 = preg_replace(&quot;\/'\/&quot;, '&amp;apos;', $txt1);\r\necho $txt2;\r\n<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n<pre class=\"my_pre\">\r\nAAA&apos;B&apos;CCC\r\n<\/pre>\n<p>WEB\u30d6\u30e9\u30a6\u30b6\u3067\u8868\u793a\u3059\u308b\u3068\u5909\u63db\u524d\u5f8c\u306e\u9055\u3044\u304c\u308f\u304b\u3089\u306a\u3044\u304c\u3001\u30bd\u30fc\u30b9\u3092\u958b\u3044\u3066\u307f\u308b\u3068\u5909\u308f\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308b\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/php\/wp-content\/uploads\/2017\/11\/Image2.png\" alt=\"\" \/><\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u5099\u5fd8\u9332\u3002 1) \u7279\u5b9a\u306eHTML\u30bf\u30b0\u3092\u9664\u53bb\u3059\u308b\u3002 &lt;img src=&#8221;xxxxx.gif&#8221;&gt;\u3092\u9664\u53bb\u3059\u308b\u3002 $txt1 = &#8216;AAAAA&lt;img src=&#038;quo\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/php\/blog46\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1491","post","type-post","status-publish","format-standard","hentry","category-17"],"views":4144,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/1491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/comments?post=1491"}],"version-history":[{"count":34,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/1491\/revisions"}],"predecessor-version":[{"id":1623,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/1491\/revisions\/1623"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/media?parent=1491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/categories?post=1491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/tags?post=1491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}