How to insert a string inside another string?

后端 未结 3 870
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 22:18

Just looked at function

str_pad($input, $pad_length, $pad_str, [STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH])

which helps to pad some str

3条回答
  •  我在风中等你
    2020-12-29 22:28

    You're looking for a string insert, not a padding.

    Padding makes a string a set length, if it's not already at that length, so if you were to give a pad length 3 to "abcdef", well it's already at 3, so nothing should happen.

    Try:

    $newstring = substr_replace($orig_string, $insert_string, $position, 0);
    

    PHP manual on substr_replace

提交回复
热议问题