I’ve now discovered that the problem wasn’t with any WordPress files as such, but with the underlying database. The comments table in the database had crashed and could not be auto-repaired. I had to manually repair it via phpMyAdmin and then it was up and running again.
Thanks for that suggestion.
I’ve installed a fresh copy of the /wp-includes/formatting.php file and then gone back to the default theme/switched off all plugins. Unfortunately, I’m still getting the same error message.
Yes, I’ve now tried that strategy again to make sure (switched off all plugins and switched to the clean default theme). The problem doesn’t go away.
I’m not sure what else to try.