Smart quotes problem
Smart quotes problem
Hi, I'm getting problem with people pasting in text that contains 'smart quotes'. (i.e. ' pasted from Word - ‘hello’) My question is, is there a master place in the code where I can perhaps add a catchall mysqli_real_escape_string so that when someone copies and pastes, say This is ‘some’ text - using smartquotes instead of keyboard quote it doesn't error? Or is there a better answer? Any thoughts appreciated. Thanks.
Re: Smart quotes problem
I recall I've struck this problem before and am pretty sure I fixed it with javascript at the time of pasting, triggered by an event listener.
This is untested but you could try the following.
Assuming it is all <textarea> elements you are having problems with, you could try adding the script below to your hooks/header-extras.php
Hopefully that should work.
(for <input> elements, just replace the TEXTAREA tagName with INPUT .....etc)
This is untested but you could try the following.
Assuming it is all <textarea> elements you are having problems with, you could try adding the script below to your hooks/header-extras.php
Code: Select all
<script>
// Listen for any input event on textareas within the document
document.addEventListener('input', function(event) {
// Check if the event target is a textarea
if (event.target.tagName === 'TEXTAREA') {
const textarea = event.target;
// Replace smart double quotes (“ ”) with straight quotes (" ")
textarea.value = textarea.value.replace(/[\u201C\u201D]/g, '"');
// Replace smart single quotes (‘ ’) with straight quotes (' ')
textarea.value = textarea.value.replace(/[\u2018\u2019]/g, "'");
}
});
</script>
(for <input> elements, just replace the TEXTAREA tagName with INPUT .....etc)
Re: Smart quotes problem
Thank peebee, I can see why that should work and just tried it but without success. I'll try and tweak it but if anyone can spot what's stopping it from working I'd be happy to hear. Thanks. Graham
Re: Smart quotes problem
I think smart quotes shouldn't be an issue, is it because the locale (character encoding in AppGini project page) you are using is not unicode?