zfred09 Posted July 5, 2007 Share Posted July 5, 2007 Say I had $string = "I swear I have seen this before."; I want to add $addme = "**"; into the original string after 10 characters. How would I do this? Link to comment https://forums.phpfreaks.com/topic/58590-insert-string-into-string-based-on-number-of-chars/ Share on other sites More sharing options...
GingerRobot Posted July 5, 2007 Share Posted July 5, 2007 Just need to use substr(): <?php $string = "I swear I have seen this before."; $addme = '**'; $add_after = '10'; $new_string = substr($string,0,$add_after).$addme.substr($string,$add_after); echo $new_string; ?> Link to comment https://forums.phpfreaks.com/topic/58590-insert-string-into-string-based-on-number-of-chars/#findComment-290621 Share on other sites More sharing options...
zfred09 Posted July 5, 2007 Author Share Posted July 5, 2007 Ok, that seems to work. Thanks. Link to comment https://forums.phpfreaks.com/topic/58590-insert-string-into-string-based-on-number-of-chars/#findComment-290622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.