$txt = "This_is_a_song_.mp3"; substr($txt, rindex($txt, '_'), 1) = ''; print $txt;