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

  • Home
  • SEARCH
  • 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 8923995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:17:00+00:00 2026-06-15T07:17:00+00:00

I know there’s a json_encode on php. currently we are using that. But it’s

  • 0

I know there’s a json_encode on php. currently we are using that. But it’s the only thing that slows the app down cause it needs to go to the server.

Here’s the situation, we 2 apps. Let’s call them app1 and app2.

App1 is a big application. One of it’s input is a php array.

Now app2 on the other hand is a small application created to help app1. App2 has a form. The form has many many fields. Then all of these fields will be converted to the correct php array format, ready to be used as an input in app1.

Now our problem, every time we use app2, we should be more careful or always keep the fields. Cause if there’s one field with wrong info, we need to do it again, use app2 to get the correct array.

So, we think we need to add a feature on app2. We want it to be able to edit the php array it produce. We’ve done that. When php array is given, we send it to server, use json_encode, then put everything in place. Now we have all the fields populated and we can then edit the fields with incorrect data.

At the moment, we are okay with that, but I think it would be more efficient to not go to the server and just convert the php array using js… I’ve searched google and stackoverflow, I found nothing. I did try using .replace(), but I haven’t figured it out yet a good result..

I’m hoping someone can help me here..

EDIT:

it’s a PHP array format by the way…

as simple example we have to input fields. After filling out the fields it will output a PHP array format in textarea.

  • 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-15T07:17:02+00:00Added an answer on June 15, 2026 at 7:17 am

    From your comment, you seem to be saying you have a string in a textarea like this:

    <textarea>array('a'=>'goat', 'b' => 'dog')</textarea>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    I really don’t understand why your app would be putting any “code” type result in a textarea in the first place, let alone a string that is a PHP format array literal, but to attempt to answer your question about how to use JavaScript to turn such a string into a JS object, you can do this:

    // assuming your textarea has the id "myTextArea":
    var str = document.getElementById("myTextArea").value,
        json = "{" + str.slice(6, -1).replace(/=>/g,":").replace(/'/g,"\"") + "}";
    console.log(json);
    var obj = JSON.parse(json);
    console.log(obj);
    

    Demo: http://jsfiddle.net/WknYX/

    I put the two console.log() statements in so that you can see what the string looks like after it’s been manipulated into JSON format, and then see the resulting object once that JSON has been parsed.

    Note that obviously this code will break with an error if the string is in any other format, and if the items in the array contain the characters that are being replaced that would not give an error but would give incorrect results.

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

Sidebar

Related Questions

I know there are dozens of questions that ask about this error, but none
I know there's a hard way to do that (not that hard, but not
I know there's an isspace function that checks for spaces, but that would require
I know there are many threads that talk about this problem but I don't
I know there are lots of tools on the net that can make our
I know there is a lot on this topic but I can't get any
I know there are a lot of similar questions on SF, but I think
I know there is a wiki page about it , but since I'm very
I know there are a lot of questions around on this subject, but I've
I know there are many discussions about the emulator which is so slow that

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.