I’m using TINYMCE text editor and if you use a double space the string gets cut off. So if I write:
a a a a — it will output as — a a a — since there’s a double space after the third a. I tried:
$text = preg_replace('/[ ]+/', ' ', $text);
Which doesn’t work and I set:
<meta charset="UTF-8" />
This is sooo weird… what would cause this? Thank you
UPDATE
Here’s the code still not working…
jQuery / Ajax
$('#page_left_comment_submit').click(function() {
var comment = tinyMCE.activeEditor.getContent(); // This how you retrieve data with TINYMCE
$.ajax({
type: 'POST',
url: '........',
data: 'comment=' + comment,
success: function(data) {
$('#music_spot_comment_result_all_holder_top')..html(data);
}
});
});
PHP
if(isset($_POST['comment'])) {
$comment = $_POST['comment'];
$comment = preg_replace('/\s+/', ' ', $comment);
echo $comment;
}
Var dump After
This is a a a (double space) a
string(9) "
a a a "
Before
Same string as above
string(9) "
a a a "
UPDATE
I’m doing this in the javascript to eliminate double spaces:
var comment = comment.replace(/ /g,'');
The regular expression for
whitespaceis\s.In your case: