{"id":2038,"date":"2022-03-29T23:41:20","date_gmt":"2022-03-29T14:41:20","guid":{"rendered":"https:\/\/www.dogrow.net\/php\/?p=2038"},"modified":"2022-03-30T00:04:32","modified_gmt":"2022-03-29T15:04:32","slug":"blog78","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/php\/blog78\/","title":{"rendered":"(78) \u5168\u89d2\u30b9\u30da\u30fc\u30b9\u3092 trim\u3067\u9664\u53bb\u3057\u305f\u3044\u3002"},"content":{"rendered":"<h1 class=\"my_h\">1. \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>PHP\u306e\u95a2\u6570 <span class=\"my_fc_deeppinkBBig\">trim($str)<\/span> \u3067\u306f\u3001<br \/>\n\u6587\u5b57\u5217 $str \u306e\u524d\u5f8c\u306b\u4ed8\u3044\u305f\u7a7a\u767d\u6587\u5b57\u3092\u9664\u53bb\u3057\u3066\u304f\u308c\u308b\u3002<\/p>\n<p>\u3057\u304b\u3057&#8230;<br \/>\n\u5168\u89d2\u30b9\u30da\u30fc\u30b9\u306f\u3001\u7a7a\u767d\u6587\u5b57\u3068\u3057\u3066\u8a8d\u8b58\u3057\u3066\u304f\u308c\u306a\u3044\u3002<\/p>\n<p>\u3053\u308c\u306b\u5bfe\u5fdc\u3057\u305f\u51e6\u7406\u3001\u3059\u306a\u308f\u3061\u3001\u304a\u305d\u3089\u304f\u8ab0\u3082\u304c\u691c\u7d22\u3057\u3066\u307f\u305f\u306b\u9055\u3044\u306a\u3044<br \/>\n<span class=\"my_fc_deeppinkBBig\">mb_trim($str)<\/span><br \/>\n\u3092\u5b9f\u88c5\u3057\u3066\u307f\u305f\u3044\u3002<\/p>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b<\/h1>\n<p>PHP\u306e\u95a2\u6570 <span class=\"my_fc_deeppinkBBig\">preg_replace()<\/span> \u3067\u306f<br \/>\n\u30d1\u30bf\u30fc\u30f3\u306b\u7a7a\u767d\u6587\u5b57\u300c\\s\u300d\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u3001\u5168\u89d2\u30b9\u30da\u30fc\u30b9\u3001\u30bf\u30d6\u6587\u5b57\u306b\u5bfe\u3057\u3066\u51e6\u7406\u3057\u3066\u304f\u308c\u308b\u3002<br \/>\n\u3053\u308c\u3092\u4f7f\u304a\u3046\u3002<\/p>\n<p>PHP\u516c\u5f0f\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9: <a href=\"https:\/\/www.php.net\/manual\/ja\/function.preg-replace.php\" target=\"_blank\" rel=\"noopener\">preg_replace<\/a><\/p>\n<h3 class=\"my_h\">(1) \u30b7\u30f3\u30d7\u30eb\u5b9f\u88c5<\/h3>\n<p>\u3053\u3093\u306a\u95a2\u6570\u3092\u4f5c\u3063\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction mb_trim( $str ){\r\n  return preg_replace(&quot;\/\\A\\s+|\\s+\\z\/u&quot;, &quot;&quot;, $str);\r\n}\r\n<\/pre>\n<p>\u7b2c\u4e00\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u30d1\u30bf\u30fc\u30f3\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8aad\u3081\u3070\u3088\u3044\u3002<br \/>\n<span class=\"my_fc_redB\">\\A\\s+<\/span> \u2192 \u5148\u982d\u300c<span class=\"my_fc_redB\">\\A<\/span>\u300d\u304b\u3089\u7a7a\u767d\u6587\u5b57\u300c<span class=\"my_fc_redB\">\\s<\/span>\u300d\u304c\u4e00\u500b\u4ee5\u4e0a\u300c<span class=\"my_fc_redB\">+<\/span>\u300d\u5b58\u5728\u3059\u308b\u5834\u5408<br \/>\n\u3000\u3082\u3057\u304f\u306f\u300c<span class=\"my_fc_blueB\">|<\/span>\u300d<br \/>\n<span class=\"my_fc_greenB\">\\s+\\z<\/span> \u2192 \u7d42\u7aef\u300c<span class=\"my_fc_greenB\">\\z<\/span>\u300d\u307e\u3067\u7a7a\u767d\u6587\u5b57\u300c<span class=\"my_fc_greenB\">\\s<\/span>\u300d\u304c\u4e00\u500b\u4ee5\u4e0a\u300c<span class=\"my_fc_greenB\">+<\/span>\u300d\u5b58\u5728\u3059\u308b\u5834\u5408<\/p>\n<p>\u3042\u3063&#8230;<br \/>\n<span class=\"my_fc_greenB\">u<\/span> \u306f Unicode\u3067\u3042\u308b\u3053\u3068\u3092\u8868\u3059\u3002<\/p>\n<p>\u3059\u306a\u308f\u3061\u3001\u95a2\u6570 preg_replace\u306b\u5bfe\u3057\u3066\u3001<br \/>\n\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u306b\u30de\u30c3\u30c1\u3057\u305f\u6587\u5b57\uff08\uff1d\u6587\u982d or \u6587\u672b\u306e\u7a7a\u767d\u6587\u5b57\uff09\u306f\u6d88\u53bb\u300c&#8221;\u300d(\uff1d\u6587\u5b57\u7121\u3057\u306b\u5909\u63db)\u3057\u3066\u3088<br \/>\n\u3068\u6307\u793a\u3057\u3066\u3044\u308b\u306e\u3060\u3002<\/p>\n<p>\u5b9f\u969b\u306b\u4f7f\u3063\u3066\u307f\u308b\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u304b\u3057\u3066\u307f\u305f\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\necho ' (1)&#x5B;'.mb_trim(&quot; ABCDEFG &quot;).']';    \/\/ \u524d\u5f8c\u306b\u534a\u89d2\u30b9\u30da\u30fc\u30b9\r\necho ' (2)&#x5B;'.mb_trim(&quot;\u3000ABCDEFG\u3000&quot;).']';  \/\/ \u524d\u5f8c\u306b\u5168\u89d2\u30b9\u30da\u30fc\u30b9\r\necho ' (3)&#x5B;'.mb_trim(&quot;\tABCDEFG\t&quot;).']';   \/\/ \u524d\u5f8c\u306b\u30bf\u30d6\u6587\u5b57\r\n<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n<a href=\"https:\/\/www.dogrow.net\/php\/sample\/00078\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.dogrow.net\/php\/sample\/00078\/<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/php\/wp-content\/uploads\/2022\/03\/i001.png\" alt=\"\" class=\"my_add_bs1\" \/><\/a><\/p>\n<p>\u3061\u3087\u3063\u3068\u898b\u3065\u3089\u3051\u308c\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7a7a\u767d\u6587\u5b57\u6307\u5b9a\u3092 <span class=\"my_fc_deeppinkBBig\">[ ]<\/span> \u3067\u62ec\u3063\u3066\u3082\u3088\u3044\u3002<br \/>\n[ ]\u5185\u306e\u4efb\u610f\u306e\u4e00\u6587\u5b57\u306b\u30de\u30c3\u30c1\u3057\u305f\u5834\u5408\u3092\u6307\u793a\u3059\u308b\u69cb\u6587\u3060\u304c\u3001\u4e2d\u8eab\u304c\u4e00\u6587\u5b57\u3060\u3051\u3067\u3082\u3088\u3044\u306e\u3060\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction mb_trim( $str ){\r\n  return preg_replace(&quot;\/\\A&#x5B;\\s]+|&#x5B;\\s]+\\z\/u&quot;, &quot;&quot;, $str);\r\n}\r\n<\/pre>\n<p>\u5c11\u3057\u898b\u3084\u3059\u304f\u306a\u3063\u305f\u304b\u3082\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>1. \u3084\u308a\u305f\u3044\u3053\u3068 PHP\u306e\u95a2\u6570 trim($str) \u3067\u306f\u3001 \u6587\u5b57\u5217 $str \u306e\u524d\u5f8c\u306b\u4ed8\u3044\u305f\u7a7a\u767d\u6587\u5b57\u3092\u9664\u53bb\u3057\u3066\u304f\u308c\u308b\u3002 \u3057\u304b\u3057&#8230; \u5168\u89d2\u30b9\u30da\u30fc\u30b9\u306f\u3001\u7a7a\u767d\u6587\u5b57\u3068\u3057\u3066\u8a8d\u8b58\u3057\u3066\u304f\u308c\u306a\u3044\u3002 \u3053\u308c\u306b\u5bfe\u5fdc\u3057\u305f\u51e6\u7406\u3001\u3059\u306a\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/php\/blog78\/\">\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":[26],"tags":[],"class_list":["post-2038","post","type-post","status-publish","format-standard","hentry","category-26"],"views":3696,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/2038","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=2038"}],"version-history":[{"count":10,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/2038\/revisions"}],"predecessor-version":[{"id":2049,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/2038\/revisions\/2049"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/media?parent=2038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/categories?post=2038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/tags?post=2038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}