php insert character into string – How to insert a string in the specified position in PHP?

php insert character into string at position $result = substr_replace($oldstr, $str_to_insert, $pos, 0);. it has a built-in substr_replace() function by using that we can insert a string at the specified position.

php insert character into string

Simple way to insert a string into another string at any position in PHP. PHP String Exercises: Insert a string at the specified position in a given string Example.

substr_replace ( $string , $replacement , $start , 0 )

Example


Insert string at specified position

$result = substr_replace($first_info, $str_to_insert, $pos, 0);

Example

$str = substr($first_info, 0, $pos) . $str_to_insert . substr($first_info, $pos);

Don't Miss : PHP Addslashes

I hope you get an idea about php insert character into string.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment