I am using window.location.href = 'mailto:?body=visit http://example.com/?content=link';
which works fine, but the way the link is built is window.location.href = 'mailto:?body=<?php echo $content; ?>';
now this works fine unless $content contains ' or something similar which breaks the code.
How can I make this work?
Use the
rawurlencodefunction[php docs] to encode any characters in your input that aren’t valid in URLs.Output:
It is true that you normally would want to use
addslashes[php docs] when you’re putting something in a quoted string. In this case it would have no effect because the output ofrawurlencodedoesn’t have any characters that need to be escaped with slashes.