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 8399297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:15:51+00:00 2026-06-09T21:15:51+00:00

I have a javascript variable which hold the value taken from somewhere else(lets say

  • 0

I have a javascript variable which hold the value taken from somewhere else(lets say from a API call), taken string is given bellow,

He's the reason for this

I assign this string to a variable name ‘sample’. But when I print it, it doesn’t work since the string has ” ‘ ” character. I want to add ” \ ” before the ” ‘ ” character. I tried using this,

var sample = (get the string from a api call).replace(/'/g,"\\\'");

But it doesn’t work?

  • 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-06-09T21:15:52+00:00Added an answer on June 9, 2026 at 9:15 pm

    in my javascript file I use window.location.href = "test.php?detail="+sample; to send the data.

    Use encodeURIComponent to escape a string for inserting into a URI.

    In my test.php, I use $detail = $_GET["detail"]; and echo $detail; to print it.

    If you are printing it into HTML then use htmlspecialcharsto make it safe.

    If you are printing it into JavaScript then use json_encode to make it safe.

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

Sidebar

Related Questions

i have to pass a string value which is stored in a variable to
i have a javascript variable which contains a string with new lines and spaces
I have session key that is a JavaScript variable which I got from a
I have a javascript variable which looks like: data = [{ y: 55.11, color:
I have a JavaScript file which has a variable as such: var ads =
I have javascript string variable with var sttr=We prefer questions that can be answered
I have a JavaScript variable I grabbed from a form field and I am
I have a javascript question. I'm trying to dynamically build a plugins string variable
I have a JavaScript variable that I echo out using PHP which is shown
I have javascript variable obj which represents an element in the DOM and I

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.