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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:06:02+00:00 2026-06-03T02:06:02+00:00

I am trying to save some data on the server but finding some encoding

  • 0

I am trying to save some data on the server but finding some encoding problems.

This is how I am sending my objects to PHP (which works fine but I don’t think the contentType is actually doing anything):

$.post(
  'myfile.php',
   {
       contentType: "application/x-www-form-urlencoded;charset=utf-8",
       data : myData
   },
   function (data, textStatus, jqXHR){
      //some code here
   }
);

and then in PHP (myfile.php):

<?php
   header('Content-Type: text/html; charset=utf-8');

   $file = 'data/theData.txt'; //the file to edit
   $current = file_get_contents($file); // Open the file to get existing content
   $a2 = json_decode( $current, true );

   $data = $_POST['data']; //the data from the webpage

   $res = array_merge_recursive( $data, $a2 );

   $resJson = json_encode( $res );

   // Write the contents back to the file
   file_put_contents($file, $resJson);
?>

As you can see I am getting the original contents of the file and decoding the json. I am then merging the result with the data sent from the webpage before re-encoding in json and put the contents back.

This all works as expected. However, at one point in my Jquery the data sent contains a wide variety of symbols like “/ ö é ł Ż ę”

When the file is saved each ‘/’ has an escape character ‘\’ in front of it and likewise the ‘é’ for example is ‘\u00e9’

How do I override this? Should I try to convert it properly in the PHP or is their a way in the JQuery to convert back to the correct format after I have $.get(‘data/theData.txt’?

Any light shed on this issue is greatly appreciated! Please excuse the poor variable names.

  • 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-03T02:06:03+00:00Added an answer on June 3, 2026 at 2:06 am

    The link provided by @chalet16 helped but if JSON_UNESCAPED_UNICODE doesn’t work for you this does the job!

    $myString = $json_encode($myObject); 
    //After initially encoding to json there are escapes on all '/' and characters like ö é ł Ż ę
    
    //First unescape slashes:
    $myString = str_replace("\/","/",$myString);
    
    //Then escape double quotes
    $myString = str_replace('"','\\"',$myString);
    
    //And Finally:
    $myNewString = json_decode('"'.$myString.'"');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to save some data for a android game, but I cant
I'm trying to save some data to A file in android, I'm using herefor
I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms
I'm trying to save some lookup table data out to a YAML file so
I'm trying to save some specific JSon data and store them in a simple
I'm trying to encrypt some data in a Python program and save it out,
I'm trying to create core data application. Some times when trying to save data,
I'm trying to save some UserControl-Infos into a List like this: List<UserControlDetails> myList; public
I'm trying to save some layouts from DevExpress Grid Controls so that users can
The idea: I'm just trying to save some Chinese characters to a MySQL database.

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.