When passing variables from JavaScript to PHP (via AJAX, perhaps, or by setting location.href), the analogue of this function is encodeURIComponent()
Example:
<?php // JavaScript actually
var comments=document.getElementById('comments').value;
var url=location.protocol+'//'+location.host+
'/handle_form.php?comments='+encodeURIComponent(comments);
location.href=url;
?>
