tbare Posted September 9, 2008 Share Posted September 9, 2008 i have a string of names: "French Stuart, Burt Reynolds, Sean Connery" and want this changed to: "French Stuart, Burt Reynolds, & Sean Connery" so, basically, i want to change the second "," to ", &"... how would this be done? Link to comment https://forums.phpfreaks.com/topic/123530-solved-change-second-occurance-in-a-string/ Share on other sites More sharing options...
The Little Guy Posted September 9, 2008 Share Posted September 9, 2008 $str = "French Stuart, Burt Reynolds, Sean Connery"; $pos = strrpos($str,","); $str = substr_replace($str," & ",$pos+1,0); echo $str; Link to comment https://forums.phpfreaks.com/topic/123530-solved-change-second-occurance-in-a-string/#findComment-637984 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 thanks!... just so i understand why, here... $str = substr_replace($str," & ",$pos+1,0); waht does the last ,0 do here? Link to comment https://forums.phpfreaks.com/topic/123530-solved-change-second-occurance-in-a-string/#findComment-637988 Share on other sites More sharing options...
The Little Guy Posted September 9, 2008 Share Posted September 9, 2008 the 0 tells it not to cut off everything after the insert. If given and is positive' date=' it represents the length of the portion of string which is to be replaced. If it is negative, it represents the number of characters from the end of string at which to stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the end of string . Of course, if length is zero then this function will have the effect of inserting replacement into string at the given start offset. [/quote'] Link to comment https://forums.phpfreaks.com/topic/123530-solved-change-second-occurance-in-a-string/#findComment-637990 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 Thanks!! works great! Link to comment https://forums.phpfreaks.com/topic/123530-solved-change-second-occurance-in-a-string/#findComment-638000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.