How can I replace a string? $ A = & quot; 1234683214312354436214214125436121436 & quot; $ B = & quot; 76234265832465867892353463476254273434252 & quot; replace the middle 1 of $ a '@'; for example, how does one replace the string with 6th in 11 cases?
$ A = "1234683214312354436214214125436121436 ";
$ B = "76234265832465867892353463476254273434252 ";
Replace the middle 1 of $ a with '@'. for example, if there are 11 1 s, replace 6th.
Replace the middle 2 in $ B with '@'. for example, if there are eight 2 S, replace 4th.
------ Solution --------------------
You can use preg_match_all + PREG_OFFSET_CAPTURE to match the information you want to replace and the offset of the matching information. what do you know next.
$ A = "1234683214312354436214214125436121436 ";
$ B = "76234265832465867892353463476254273434252 ";
Preg_match_all ('#1 #', $ a, $ match, PREG_OFFSET_CAPTURE );
Echo"
";
Print_r ($ match );
?>
------ Solution --------------------
Discussion
Reference:
No error reported twice. I fixed it.
PHP code
Function fool ($ str, $ number, $ change)
{
$ Array = str_split ($ str );
If (in_array ($ number, $ array )){
$ Key = array_keys ($ array, $ number );
$ ......