{"id":750,"date":"2025-08-01T15:34:57","date_gmt":"2025-08-01T06:34:57","guid":{"rendered":"https:\/\/nexive.tech\/?p=750"},"modified":"2025-08-01T15:34:57","modified_gmt":"2025-08-01T06:34:57","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91php%e3%81%ae%e6%96%87%e5%ad%97%e5%88%97%e6%93%8d%e4%bd%9c%e9%96%a2%e6%95%b0%e3%81%be%e3%81%a8%e3%82%81%ef%bc%88substr-str_repla","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=750","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011PHP\u306e\u6587\u5b57\u5217\u64cd\u4f5c\u95a2\u6570\u307e\u3068\u3081\uff08substr, str_replace \u306a\u3069\uff09"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP\u306b\u304a\u3051\u308b\u57fa\u672c\u7684\u306a\u6587\u5b57\u5217\u64cd\u4f5c\u95a2\u6570\uff08substr, str_replace \u306a\u3069\uff09\u3092\u89e3\u8aac<\/li>\n\n\n\n<li>\u95a2\u6570\u306e\u4f7f\u3044\u5206\u3051\u3084\u6319\u52d5\u5dee\u3001\u6ce8\u610f\u70b9\u3092\u5b9f\u884c\u53ef\u80fd\u30b3\u30fc\u30c9\u4ed8\u304d\u3067\u7d39\u4ecb<\/li>\n\n\n\n<li>\u5b9f\u52d9\u3067\u3088\u304f\u4f7f\u308f\u308c\u308b\u30d1\u30bf\u30fc\u30f3\u3084\u8a2d\u8a08\u5224\u65ad\u3082\u4ea4\u3048\u3066\u89e3\u8aac<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP\u306e\u6587\u5b57\u5217\u64cd\u4f5c\u95a2\u6570\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>PHP\u306f\u6587\u5b57\u5217\u64cd\u4f5c\u306b\u7279\u5316\u3057\u305f\u95a2\u6570\u7fa4\u304c\u8c4a\u5bcc\u306b\u7528\u610f\u3055\u308c\u3066\u304a\u308a\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306eWeb\u30a2\u30d7\u30ea\u958b\u767a\u306b\u304a\u3044\u3066\u975e\u5e38\u306b\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002\u7279\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u51e6\u7406\u3084\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3001\u5f62\u5f0f\u5909\u63db\u306a\u3069\u3001\u65e5\u5e38\u7684\u306a\u6587\u5b57\u5217\u51e6\u7406\u3067\u5fc5\u9808\u306e\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u95a2\u6570\u306f\u6a19\u6e96\u3067\u7d44\u307f\u8fbc\u307e\u308c\u3066\u304a\u308a\u3001\u8ffd\u52a0\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u3057\u3067\u4f7f\u7528\u53ef\u80fd\u3067\u3059\u3002<code>substr<\/code>\u3084<code>str_replace<\/code>\u3068\u3044\u3063\u305f\u57fa\u672c\u7684\u306a\u3082\u306e\u304b\u3089\u3001\u6b63\u898f\u8868\u73fe\u3092\u5229\u7528\u3059\u308b<code>preg_replace<\/code>\u3001\u30d0\u30a4\u30c8\u6570\u306b\u4f9d\u5b58\u305b\u305a\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u306b\u5bfe\u5fdc\u3057\u305f<code>mb_substr<\/code>\u306a\u3069\u3082\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001\u3053\u308c\u3089\u306e\u4e2d\u304b\u3089\u5b9f\u52d9\u3067\u983b\u7e41\u306b\u767b\u5834\u3059\u308b\u4ee3\u8868\u7684\u306a\u95a2\u6570\u3092\u53d6\u308a\u4e0a\u3052\u3001\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u304b\u3089\u8aa4\u7528\u3057\u3084\u3059\u3044\u30dd\u30a4\u30f3\u30c8\u307e\u3067\u6574\u7406\u3057\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\uff1asubstr()<\/h3>\n\n\n\n<p>\u7279\u5b9a\u306e\u4f4d\u7f6e\u304b\u3089\u6587\u5b57\u5217\u306e\u4e00\u90e8\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u6587\u5b57\u5217\u306e3\u6587\u5b57\u76ee\u304b\u30894\u6587\u5b57\u53d6\u5f97\u3059\u308b\n$text = \"abcdefg\";\n$sub = substr($text, 2, 4); \/\/ \u958b\u59cb\u4f4d\u7f6e2\uff080\u59cb\u307e\u308a\uff09\u3001\u9577\u30554\n\necho $sub; \/\/ \u51fa\u529b: \"cdef\"\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u6587\u5b57\u5217\u306e3\u6587\u5b57\u76ee\u304b\u30894\u6587\u5b57\u53d6\u5f97\u3059\u308b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;abcdefg&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$sub<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">substr<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ \u958b\u59cb\u4f4d\u7f6e2\uff080\u59cb\u307e\u308a\uff09\u3001\u9577\u30554<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$sub<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: &quot;cdef&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u5f15\u6570 <code>$start<\/code> \u306f0\u59cb\u307e\u308a\u3001\u8ca0\u6570\u3092\u6307\u5b9a\u3059\u308b\u3068\u5f8c\u308d\u304b\u3089\u6570\u3048\u307e\u3059\u3002\u9577\u3055 <code>$length<\/code> \u3092\u7701\u7565\u3059\u308b\u3068\u672b\u5c3e\u307e\u3067\u62bd\u51fa\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u672b\u5c3e\u304b\u30893\u6587\u5b57\u53d6\u5f97\n$text = \"abcdefg\";\necho substr($text, -3); \/\/ \u51fa\u529b: \"efg\"\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u672b\u5c3e\u304b\u30893\u6587\u5b57\u53d6\u5f97<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;abcdefg&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">substr<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\">, -<\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: &quot;efg&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u5217\uff08\u65e5\u672c\u8a9e\u306a\u3069\uff09\u3092\u6271\u3046\u5834\u5408\u306f <code>mb_substr()<\/code> \u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u5b57\u5217\u3092\u7f6e\u63db\uff1astr_replace()<\/h3>\n\n\n\n<p>\u6587\u5b57\u5217\u4e2d\u306e\u7279\u5b9a\u90e8\u5206\u3092\u7f6e\u63db\u3057\u307e\u3059\u3002\u914d\u5217\u3067\u8907\u6570\u6307\u5b9a\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$text = \"I like apples.\";\n$newText = str_replace(\"apples\", \"oranges\", $text);\n\necho $newText; \/\/ \u51fa\u529b: \"I like oranges.\"\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;I like apples.&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$newText<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">str_replace<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;apples&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;oranges&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$newText<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: &quot;I like oranges.&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u8907\u6570\u30ef\u30fc\u30c9\u3092\u4e00\u62ec\u7f6e\u63db\u3057\u305f\u3044\u5834\u5408\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$text = \"red green blue\";\n$newText = str_replace(&#91;\n  \"red\", \"green\"\n&#93;, &#91;\"orange\", \"yellow\"&#93;, $text);\n\necho $newText; \/\/ \u51fa\u529b: \"orange yellow blue\"\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;red green blue&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$newText<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">str_replace<\/span><span style=\"color: #D4D4D4\">(&#91;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #CE9178\">&quot;red&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;green&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">&#93;, &#91;<\/span><span style=\"color: #CE9178\">&quot;orange&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;yellow&quot;<\/span><span style=\"color: #D4D4D4\">&#93;, <\/span><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$newText<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: &quot;orange yellow blue&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u691c\u7d22\u8a9e\u3068\u7f6e\u63db\u8a9e\u306e\u914d\u5217\u30b5\u30a4\u30ba\u304c\u7570\u306a\u308b\u3068\u3001\u4f59\u3063\u305f\u8981\u7d20\u306f\u7121\u8996\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u6b63\u898f\u8868\u73fe\u3067\u7f6e\u63db\uff1apreg_replace()<\/h3>\n\n\n\n<p>\u6b63\u898f\u8868\u73fe\u306b\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u3092\u7f6e\u63db\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$text = \"Phone: 090-1234-5678\";\n$masked = preg_replace(\"\/\\d{2,4}-\\d{2,4}-\\d{4}\/\", \"***-****-****\", $text);\n\necho $masked; \/\/ \u51fa\u529b: \"Phone: ***-****-****\"\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;Phone: 090-1234-5678&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$masked<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">preg_replace<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #D16969\">&quot;\/\\d{2,4}-\\d{2,4}-\\d{4}\/&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;***-****-****&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$masked<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: &quot;Phone: ***-****-****&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><code>str_replace()<\/code> \u3067\u306f\u67d4\u8edf\u306b\u5bfe\u5fdc\u3067\u304d\u306a\u3044\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u306b\u6709\u52b9\u3067\u3059\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u5bfe\u5fdc\uff1amb_substr()<\/h3>\n\n\n\n<p>\u65e5\u672c\u8a9e\u306a\u3069\u306e\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u5217\u306e\u90e8\u5206\u53d6\u5f97\u306b\u306f <code>mb_substr()<\/code> \u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$text = \"\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\";\n$sub = mb_substr($text, 2, 3); \/\/ \u300c\u306b\u3061\u306f\u300d\n\necho $sub; \/\/ \u51fa\u529b: \"\u306b\u3061\u306f\"\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;\u3053\u3093\u306b\u3061\u306f\u4e16\u754c&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$sub<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">mb_substr<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$text<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ \u300c\u306b\u3061\u306f\u300d<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$sub<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: &quot;\u306b\u3061\u306f&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><code>substr()<\/code>\u3092\u65e5\u672c\u8a9e\u306b\u4f7f\u3046\u3068\u6587\u5b57\u5316\u3051\u3084\u4e00\u90e8\u6b20\u843d\u306e\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>substr()<\/code>\u3067\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u3092\u6271\u3046\u3068\u3001\u9014\u4e2d\u3067\u6587\u5b57\u304c\u5207\u308c\u3066\u6587\u5b57\u5316\u3051\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u65e5\u672c\u8a9e\u306b\u306f<code>mb_substr()<\/code>\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002<\/li>\n\n\n\n<li><code>str_replace()<\/code>\u306e\u691c\u7d22\u30fb\u7f6e\u63db\u914d\u5217\u306e\u9577\u3055\u304c\u4e00\u81f4\u3057\u306a\u3044\u5834\u5408\u3001\u60f3\u5b9a\u901a\u308a\u306b\u51e6\u7406\u3055\u308c\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>preg_replace()<\/code>\u4f7f\u7528\u6642\u306f\u3001\u6b63\u898f\u8868\u73fe\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u3084\u30d1\u30bf\u30fc\u30f3\u8aa4\u308a\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/li>\n\n\n\n<li>PHP\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u306f\u3001<code>mbstring<\/code>\u62e1\u5f35\u304c\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u304c\u3042\u308b\u305f\u3081\u3001\u4e8b\u524d\u78ba\u8a8d\u304c\u5fc5\u8981\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>PHP\u306e\u6587\u5b57\u5217\u64cd\u4f5c\u95a2\u6570\u306f\u975e\u5e38\u306b\u5f37\u529b\u3067\u3042\u308a\u3001\u9069\u5207\u306b\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u3067\u67d4\u8edf\u306a\u6587\u5b57\u5217\u51e6\u7406\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5358\u7d14\u306a\u90e8\u5206\u62bd\u51fa\u306f <code>substr()<\/code>\u3001\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u5217\u306b\u306f <code>mb_substr()<\/code><\/li>\n\n\n\n<li>\u56fa\u5b9a\u7f6e\u63db\u306b\u306f <code>str_replace()<\/code>\u3001\u67d4\u8edf\u306a\u30de\u30c3\u30c1\u30f3\u30b0\u306b\u306f <code>preg_replace()<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u65e5\u672c\u8a9e\u306a\u3069\u306e\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u3092\u6271\u3046\u5834\u9762\u304c\u591a\u3044\u5834\u5408\u306f\u3001\u5e38\u306b <code>mb_<\/code> \u7cfb\u306e\u95a2\u6570\u3092\u512a\u5148\u7684\u306b\u4f7f\u7528\u3059\u308b\u306e\u304c\u5b9f\u52d9\u4e0a\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. PHP\u306e\u6587\u5b57\u5217\u64cd\u4f5c\u95a2\u6570\u3068\u306f\uff1f PHP\u306f\u6587\u5b57\u5217\u64cd\u4f5c\u306b\u7279\u5316\u3057\u305f\u95a2\u6570\u7fa4\u304c\u8c4a\u5bcc\u306b\u7528\u610f\u3055\u308c\u3066\u304a\u308a\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306eWeb\u30a2\u30d7\u30ea\u958b\u767a\u306b\u304a\u3044\u3066\u975e\u5e38\u306b\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002\u7279\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u51e6\u7406\u3084\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3001\u5f62 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":557,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-750","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=750"}],"version-history":[{"count":1,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/750\/revisions"}],"predecessor-version":[{"id":751,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/750\/revisions\/751"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/557"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}