+ 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 */ ?>
2 Antworten
+ 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)
0
Ya ya aku suka jawaban mu, terimakasih telah berbagi pengetahuan..
You have a instagram account ?