How to remove the first occurrence of a character from a string in PHP

1 Answer

0 votes
$str = 'c c++, nodejs, python, php java c#';

$ch = 'p';

$str = substr_replace($str, '', strpos($str, $ch), 1);

echo $str;




/*
run:

c c++, nodejs, ython, php java c#

*/

 



answered Apr 17, 2022 by avibootz
...