Simple method for reliably detecting code in text?
We just deployed a method that we think is quite reliable for blocking 98% of posts submitted with code that has improper code formatting (or no code formatting at all).
For example, when I go into Chrome incognito and attempt to ask this question body on Stack Overflow right now:
I needed to add up all the rows for a result. Using the select_sum as follows
Here is the model
$query = $this->db->select_sum('Dues_Paid', 'Dues_Paid_Tot');
$query = $this->db->get('Membership');
Here is the controller
$date = $this->input->post('Select_Date');
if($query = $this->report_model->fiscal_list($date))
$data['records'] = $query;
$data['date'] = $this->input->post('Select_Date');
$data['Dues_Paid_Tot'] = $this->report_model->Dues_Paid_Tot($date);
$data['main_content'] = 'report_fiscal_view';
I get back:
Oops! Your question couldn't be submitted because:
Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.
This check is limited to users with <= 50 reputation and is performed on questions / answers / edits and suggested edits.
If you see or hear of any cases where this is triggered inappropriately -- or not triggered, and it should have been -- let us know.