Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
何も上書きせずに特定のポイントで PHP 文字列にテキストを挿入するにはどうすればよいですか?
長さの値が0のsubstr_replace()を使用します。
コード:
substr_replace("abcdefgh","-bbbb-",3,0);
上記の出力は「abc-bbbb-defgh」になります
シンプル、使用substr():
substr()
$str_a = "foo bar"; $str_b = substr($str_a, 0, 3) . ' baz' . substr($str_a, 3);