I'm using the CKEDITOR to write a description and a summary gets auto added. The summary has a character count to stop at 300 characters. The following is a test line I wrote hitting return to take a new line.
This is a line and
a new line doesn't count
the same as php
This results in JS = 59 chars and PHP = 61 chars. The new line is getting parsed differently somehow. This leads to a serverside error when chacking if the summary is more than 300 chars because the JS says 300 but PHP is getting maybe 302
CKEDITOR.replace('description');
CKEDITOR.instances['description'].on('key', function() {
var html = CKEDITOR.instances['description'].getData();
var value = $('<div/>', { html: html }).text();
if(value.length > 300){
var text = value.substring(0, 297);
$('#summary').html(text + '...');
} else {
$('#summary').html(value);
}
char_count(limit);
});