cyfer65 Posted November 5, 2011 Share Posted November 5, 2011 how can i replace only one occurrence of a string in a main string if there are multiple occurrences of it..?if there are 3 occurrences in the main string how can I only replace the 2nd occurrence..? Link to comment Share on other sites More sharing options...
Ingolme Posted November 5, 2011 Share Posted November 5, 2011 A combination of strpos() and subsrt_replace()The substr_replace() method has two parameters indicating the start and length of the portion to remove, and one parameter for the string to put in that location. Use strpos() to figure out the first position, then use strpos() again, using the index returned by the first one to find the second occurence. The length of the string you're searching for should be used as the length used in the substr_replace() method. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.