PHP Removing one letter from a long string only once?
6 answers
You can also use str_relpace with the $ count parameter: $ str = 'djriojnrwadoiaushd'; echo str_replace ('j', '', $ str, 1);
Oops, sorry .. my bad.
Here's the real way:
$str = 'djriojnrwadoiaushd';
$pos = strpos( $str, 'j' );
if( $pos !== FALSE )
{
echo substr_replace( $str, '', $pos, 1 );
}
+4
a source to share