We help IT Professionals succeed at work.

Spcialchars in javascript similar like php

jeesrinu
jeesrinu asked
on
229 Views
Last Modified: 2012-05-08
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

Comment
Watch Question

Hi jeesrinju,

Can you check the following url and let me know,

https://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_20999435.html

Thanks

Author

Commented:
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
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.