This also was about to drive me crazy so I will not let it go without writing about it..
Let’s say you have some long HTML code contained on a PHP variable, something like this
<?php $some_div = ' <div id="box"> <h1>Title</h1> <p>Article contents + comments</p> <div>'; ?>
- Encode the html code in PHP using urlencode
When using PHP’s urlencode function, all whitespace characters will be replaced by + signs, so we’d better deal with those characters before encoding them, otherwise, we won’t make a difference between spaces and real + signs, please read the comment on the PHP code below to understand: