Link to home
Start Free TrialLog in
Avatar of jeesrinu
jeesrinu

asked on

Spcialchars in javascript similar like php

Hi,


When i run this below code it is not woking Properly

I want to expect the output as

<?php function zz(& $x) { $x=$x+5; }?>

How can display in javascript by using document.write method .Please help me


Thanks in advance



 <?
echo "test";
?>
<script>
function htmlspecialchars(str) {
 if (typeof(str) == "string") {
 alert((str));
  str = str.replace(/&/g, "&amp;"); /* must do &amp; first */
  str = str.replace(/"/g, "&quot;");
  str = str.replace(/'/g, "&#039;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  }
 return str;
 } 
document.write(htmlspecialchars('<? htmlspecialchars('<?php function zz(& $x) { $x=$x+5; }?>')?>'));
</script>

Open in new window

Avatar of seetharaml
seetharaml
Flag of India image

Hi jeesrinju,

Can you check the following url and let me know,

https://www.experts-exchange.com/questions/20999435/Blocking-Special-Characters.html

Thanks
Avatar of jeesrinu
jeesrinu

ASKER

Hi seetharaml,

 
     I am not  getting  Proper solution from this link . I have already used the regular expressions.  In my coding  please see the 7 th line alert(str) can displayed the blank alert box. Have any ideas please help me
ASKER CERTIFIED SOLUTION
Avatar of seetharaml
seetharaml
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial