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? Quote Link to comment 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; Quote Link to comment 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? Quote Link to comment 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'] Quote Link to comment Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 Thanks!! works great! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.