Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6100423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:23:05+00:00 2026-05-23T13:23:05+00:00

Is php htmlspecialchars safety for JS? var jsVar = <?php echo(str_replace(array(\r\n, \n,\r), \\n,htmlspecialchars($_GET[‘p’], ENT_QUOTES)));

  • 0

Is php htmlspecialchars safety for JS?

var jsVar = "<?php echo(str_replace(array("\r\n", "\n","\r"), "\\n",htmlspecialchars($_GET['p'], ENT_QUOTES))); ?>";

How about for multi byte chars?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:23:06+00:00Added an answer on May 23, 2026 at 1:23 pm

    No. For that you’d use json_encode (JSON = Javascript notation).

    var foo = <?php echo json_encode('Foo "Bar" Baz'); ?>;
    

    htmlspecialchars escapes characters that have a special meaning in HTML. Javascript literals have other special characters you need to take care of, so HTML escaping doesn’t make sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
var loc_name = document.forms['create_<?php echo(htmlspecialchars($window_ID)); ?>'].elements['location_name']; alert(loc_name); This just gives me the message 'undefined'
<?php $new = htmlspecialchars(<a href='test'>Test</a>, ENT_QUOTES); echo $new; ?> output should be & lt;a
How do I run the PHP function htmlspecialchars() on an array of array objects?
<?php $ip = htmlspecialchars($_GET[ip]); $serverIp = a; $a = a; include(mysql.php); $votes = serverVotes;
PHP's explode function returns an array of strings split on some provided substring. It
In PHP it's possible to have arrays in $_GET , $_POST , $_COOKIE ,
I have the existing code: <form action=page.php?id=<?= $_GET['id'] ?> method=post> <fieldset> <p id=edit_name><label for=name>Page
Here's my code: <html> <head> <?php function getValue($field){ if(isset($_GET[$field])){ return $_GET[$field]; } else{ return
Here's what I have: <html> <head> <?php $validForm = false; function getValue($field){ if(isset($_GET[$field])){ return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.