play_ Posted July 7, 2006 Share Posted July 7, 2006 I need to insert some characters at a certain position in a string.for example:$str = "12345678";so at position 8, i would want to insert a '9'.i've tried str_pad() but it isn't doing the job.and substr_replace() would work fine IF it didn't actually replace the other charatcers, just inserted them in there.ps: i just noticed how the title of this thread doesn't make much sense. sorry about that. it's 8:30am and i have yet to sleep. Link to comment https://forums.phpfreaks.com/topic/13944-inserting-characters-in-the-a-certain-position-in-a-string-not-array/ Share on other sites More sharing options...
GingerRobot Posted July 7, 2006 Share Posted July 7, 2006 Im pretty sure you can you substr_replace:$var = "1234678";echo substr_replace($var,'5',4,0);That would then output 12345678 Link to comment https://forums.phpfreaks.com/topic/13944-inserting-characters-in-the-a-certain-position-in-a-string-not-array/#findComment-54352 Share on other sites More sharing options...
play_ Posted July 7, 2006 Author Share Posted July 7, 2006 Thanks ginger.I Just actually went to read the manual (function by function in the 'strings' category) until i reached chunk_split() and it seems to work fine so far. Link to comment https://forums.phpfreaks.com/topic/13944-inserting-characters-in-the-a-certain-position-in-a-string-not-array/#findComment-54368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.