Forum Moderators: open

Message Too Old, No Replies

Javascript html character problems

         

eternal

2:19 pm on Jun 17, 2007 (gmt 0)

10+ Year Member



Hi I am passing a php variable:

$text = "example ¾"

Into javascript:

var message="<?=$text2?>"

Then outputting it:

document.write('<span id="neonlight'+m+'">'+message.charAt(m)+'</span>')

This is outputting &#190; and not the correct html character.

Is there a way around this?

penders

3:11 pm on Jun 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your 'html character' is only a singular html character when it is actually output in the browser window, until that point it is just the sequence of characters '&','#','1','9','0',';'.

I would have said that you need to convert it to the 'real character' back in the PHP, instead of using the html entity &#190; ...?

You could try using the html_entity_decode() [uk.php.net] PHP function, like:

$text = 'example '.html_entity_decode('&#190;');

...?

eternal

3:16 pm on Jun 17, 2007 (gmt 0)

10+ Year Member



Nice! That works well, thank you very much.