[FONT=Courier New][COLOR=#0000bb]<?php
[/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000bb]str_replace_count[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$search[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$replace[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$times[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]) {
[/COLOR][COLOR=#0000bb]$subject_original[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]$subject[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];
[/COLOR][COLOR=#0000bb]$len[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$search[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]$pos[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]0[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];
for ([/COLOR][COLOR=#0000bb]$i[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000bb]$i[/COLOR][COLOR=#007700]<=[/COLOR][COLOR=#0000bb]$times[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000bb]$i[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]++) {
[/COLOR][COLOR=#0000bb]$pos[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]strpos[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$search[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$pos[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);
if([/COLOR][COLOR=#0000bb]$pos[/COLOR][COLOR=#007700]!==[/COLOR][COLOR=#0000bb]false[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]) {
[/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]substr[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$subject_original[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$pos[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700].=[/COLOR][COLOR=#0000bb]$replace[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];
[/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700].=[/COLOR][COLOR=#0000bb]substr[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$subject_original[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$pos[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000bb]$len[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]$subject_original[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000bb]$subject[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];
} else {
break;
}
}
return([/COLOR][COLOR=#0000bb]$subject[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]);
}
[/FONT][/COLOR][FONT=Courier New][COLOR=#ff8000]/* Example usage */
[/COLOR][COLOR=#0000bb]$w[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#dd0000]"abracadabra"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700];
print [/COLOR][COLOR=#0000bb]str_replace_count[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"abra"[/COLOR][COLOR=#007700],[/COLOR][COLOR=#dd0000]"----"[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$w[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]2[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]);
[/COLOR][COLOR=#0000bb]?>[/COLOR][/FONT]