What do you think about this ? Or maybe, your function more simple. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What do you think about this ? Or maybe, your function more simple.

Function chr_edt() : Change or Erase a character. ---------------------------------------------------------------- <?php function chr_edt($string, $find, $new_char="", $index=0) { $var_a = strlen($string); while($index < $var_a) { if($string[$index] == $find) { $string[$index] = $new_char; } $index++; } return $string; } echo chr_edt("AAA BBB CCC ABC DAE", "A", "1", 2); /* AA1 BBB CCC 1BC D1E */ ?>

13th Feb 2017, 10:41 AM
M Hafiz Prasetyo
M Hafiz Prasetyo - avatar
2 Answers
+ 1
something like this : <?php function chr_edit($string,$needle,$replace,$skip) { return substr($string,0,-strlen($string)+$skip). str_replace($needle,$replace,substr($string,-strlen($string)+$skip)); } echo chr_edit("AAA BBB CCC ABC DAE","A","1",2); p.s.: if you don't need to use index, you can just use str_replace($search,$replace,$string)
14th Feb 2017, 3:45 PM
spiil hellig
spiil hellig - avatar
0
Ya ya aku suka jawaban mu, terimakasih telah berbagi pengetahuan.. You have a instagram account ?
14th Feb 2017, 4:46 PM
M Hafiz Prasetyo
M Hafiz Prasetyo - avatar