note 88711 deleted from function.urlencode by danbrown
| From: | danbrown@php.net | Date: | Wed, 04 Feb 2009 18:42:35 +0000 |
| Subject: | note 88711 deleted from function.urlencode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150217@lists.php.net to get a copy of this message | ||
Note Submitter: dominik dot hofer at gmx dot net
----
I read a UTF-8 encoded string form a mysql database and wanted to use it as a parameter for
a javascript function which opens a popup window (the HTML site also encoded as UTF-8).
Somehow I had serious trouble with strings containing special characters like ' and especially
german umlaute.
When using urlencode(), the umlaute weren't correctly displayed in the popup with IE.
I tried many variations with urlencode(), rawurlencode(), addslashes(), ...,
but none of them was working in all browsers (Safari, FF, IE).
If someone is experiencing the same problem:
Here is the code I got it finally working with very well in all browsers...
<?php
echo '<a href="javascript: popup_textanswer(\''.
htmlentities(addslashes($act_question['questiontext']),
ENT_QUOTES,'UTF-8').
'\');">question</a>';
?>
the javascript function:
<?php // actually javascript
function popup_textanswer(questiontext) {
var win = window.open('popup.php?id=1&questiontext=' +
questiontext, 'popup', 'width=600,height=400');
win.focus();
}
?>