Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > How to convert HTML special characters to the real characters with a Java script

Reply
Thread Tools

How to convert HTML special characters to the real characters with a Java script

 
 
Stefan Mueller
Guest
Posts: n/a
 
      03-21-2006
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(). It converts all
HTML entities to their applicable characters from string.


 
Reply With Quote
 
 
 
 
Toby Inkster
Guest
Posts: n/a
 
      03-21-2006
Stefan Mueller wrote:

> echo "var_old_data = '" . $html_data . "';";


At a guess... you're pasting $html_data into a section of Javascript --
i.e. you're pasting HTML data into something that isn't HTML. So this data
shouldn't be escaped with htmlentities().

(More technically, the stuff between <script> and </script> is CDATA, so
you don't need to do any HTML-style escaping -- you just need to avoid
using '</'.)

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
 
 
 
nice.guy.nige
Guest
Posts: n/a
 
      03-22-2006
While the city slept, Stefan Mueller ((E-Mail Removed)) feverishly
typed...

[html entities, php & js]

> 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;&#
039;
> instead of "'
>
> Therefore I need a Java script function with translates
>
>

&auml;&ouml;&uuml;&Auml;&Ouml;&Uuml;&ccedil;&eacut e;&agrave;&egrave;&quot;&#
039;
> to "'


You do indeed...... or do you?

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


Yup, you probably could...

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


Don't forget that php can be "slotted into" your html (and presumably
therefore your js code). Could you not use;

(javascript stuff...)

var content = "<? php echo(html_entity_decode($stringFullOfHtmlEntities) )
?>";

(...more javascript stuff....)

Just a thought straight off the top of my head, no idea if it will even
work!

Hope that helps,
Nige

--
Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. (E-Mail Removed) | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"


 
Reply With Quote
 
Stefan Mueller
Guest
Posts: n/a
 
      07-23-2006
> var content = "<? php echo(html_entity_decode($stringFullOfHtmlEntities) )
> ?>";


That was a super idea. It works perfect.

Many thanks
Stefan


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert MS Word special characters to HTML codes? Paul Ruby 1 04-02-2012 03:25 PM
Convert special characters from HTML to utf-8 or iso-8859-1 Axel Etzold Ruby 1 09-06-2008 11:44 PM
How to convert HTML entities to their applicable characters with a java script Stefan Mueller Javascript 3 03-21-2006 04:36 AM
Function to convert special characters? laredotornado@zipmail.com Java 5 09-02-2005 06:32 PM
Special characters in java, oracle and html Barry Olly Java 2 10-20-2003 06:01 PM



Advertisments