469,327 Members | 1,347 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

How to convert HTML entities to their applicable characters with a java script

Because the characters ', ", ... make troubles in my input boxes I use the
following PHP command while generating the page
htmlentities($my_var, ENT_QUOTES);

However, if I use in my java scripts the string generated by htmlentities it
shows
', /", ...

Is there a java script command to change
' to '
/" to "
...
?

Sterfan
Mar 20 '06 #1
3 12744
Stefan Mueller wrote:
Is there a java script command to change
Yes, use Reqular expression.
http://developer.mozilla.org/en/docs...ar_Expressions

' to ' what difference?

/" to "

Example:
var re = new RegExp("\/"");
var newText = oldText.replace(re, '"');

Mar 20 '06 #2
Stefan Mueller wrote:
Is there a java script command to change
Yes, use Reqular expression.
http://developer.mozilla.org/en/docs...ar_Expressions

' to ' what difference?

/" to "

Example:
var re = new RegExp("\/"");
var newText = oldText.replace(re, '"');

where oldText is the text that contains incorrect symbols.

Mar 20 '06 #3
Sorry that I didn't describe my problem more exact.

I read data (e.g. "') from my MySQL database which I'd like to
show in an input box.

<?php
$mysql_data = "\"'";
$html_data = addslashes(htmlentities($mysql_data, ENT_QUOTES));

echo "<script type = 'text/javascript'>";
echo "function set_old_data() {";
echo "my_form.input1.value = var_old_data;";
echo "}";
echo "var_old_data = '" . $html_data . "';";
echo "</script>";

echo "<body>";
echo "<form name = 'my_form' action = '' method = 'post' accept-charset
= 'iso-8859-1'>";
echo "<input type = 'text' name = 'input1' value = '" . $html_data .
"'>";
echo "<input type = 'button' value = 'Old Data' onClick =
'set_old_data()'>";
echo "</form>";
echo "</body>";
?>

The command
echo "<input type = 'text' name = 'input1' value = '" . $html_data . "'>";
shows my data "' in the input box perfect.

But if I click on the button 'Old Data' the Java script function
'set_old_data' shows in the input box
&auml;&ouml;&uuml;&Auml;&Ouml;&Uuml;&ccedil;&eacut e;&agrave;&egrave;&quot;'
instead of
"'

Therefore I need a Java script function with translates
&auml;&ouml;&uuml;&Auml;&Ouml;&Uuml;&ccedil;&eacut e;&agrave;&egrave;&quot;'
to
"'

In PHP I could do that with the function
html_entity_decode()

But how can I do it with a Java script?
Stefan

PS: html_entity_decode() is the opposite of htmlentities() in that it
converts all HTML entities to their applicable characters from string.
Mar 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Geoff Wilkins | last post: by
2 posts views Thread by Joergen Bech | last post: by
8 posts views Thread by dbaplusplus | last post: by
1 post views Thread by Alexander.Veit | last post: by
2 posts views Thread by Laszlo Nagy | last post: by
6 posts views Thread by clintonG | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.