473,488 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 12934
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11739
by: Geoff Wilkins | last post by:
I must confess I only come here when I have a problem - so my apologies if this has been raised before: Using my IE v.6 browser, document.write doesn't convert HTML entities (e.g. &apos;, &amp;) to...
2
2647
by: Joergen Bech | last post by:
Is there a function in the .Net 1.1 framework that will take, say, a string containing Scandinavian characters and output the corret HTML entities, such as &aelig; &oslash; &aring; etc.
2
10366
by: Albert | last post by:
How can I convert some html entities (polish) to a character which I can use in a javascript alert? The entities are: &#x0144; &#x0119; &#x0144; &#x0105; &#x017C; &#x015B; &#x0107;
6
14801
by: Stefan Mueller | last post by:
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,...
8
2368
by: dbaplusplus | last post by:
I worked on web development using java script many many years, so I am now a newbie to javascript. I have a single html page, which is generated dynamically using some programming language. Web...
1
4327
by: Alexander.Veit | last post by:
Hallo, does anyone know how to convert HTML Entities into UCS2-String (Value). For example: I need to convert Sułowska 43 (value in mysql database) to a unicode string with the specified...
2
1879
by: Laszlo Nagy | last post by:
Hi, I would like to have a function that can convert '&gt;' into '>', '&amp;' into '&' etc. I could not find how to do it easily (I have a code snippet for the opposite). Thanks, Laszlo
6
10120
by: clintonG | last post by:
Can anybody make sense of this crazy and inconsistent results? // IE7 Feed Reading View disabled displays this raw XML <?xml version="1.0" encoding="utf-8" ?> <!-- AT&T HTML entities & XML...
4
8753
by: sandeep123456 | last post by:
hi, can we send data from html to excel sheet using java script sandeep
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.