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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:20:34+00:00 2026-05-18T21:20:34+00:00

I have a .txt file with following content. [{key: HR, value: test@gmail.com}, {key: Team

  • 0

I have a .txt file with following content.

[{"key": "HR", "value": "test@gmail.com"}, {"key": "Team Leader", "value": "test1@gmail.com"}, {"key": "PM", "value": "test3@gmail.com"}, {"key": "CEO", "value": "test4@gmail.com"}]

Now ,using php if i want to add another one value like
{“key”: “new_emailid”, “value”:”test5@gmail.com”}

The output should be lik this

[{"key": "HR", "value": "test@gmail.com"}, {"key": "Team Leader", "value": "test1@gmail.com"}, {"key": "PM", "value": "test3@gmail.com"}, {"key": "CEO", "value": "test4@gmail.com"}, {"key": "new_emailid", "value":"test5@gmail.com"}]

In other words, how to add content inside the square bracket of the exisiting .txt file. Is it possible to insert a content in between the brackets. Please help me
Thanks –
Haan

  • 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-18T21:20:34+00:00Added an answer on May 18, 2026 at 9:20 pm

    Since you are dealing with JSON the safest way would be to read the txt file and load it as JSON, add a new item, and save it back. Something like this:

    $data = File_Get_Contents ( 'data.txt' );
    $data = JSon_Decode ( $data, true );
    $data[] = Array ( 'key' => 'new_emailid', 'value' => 'test5@gmail.com' );
    $data = JSon_Encode ( $data );
    File_Put_Contents ( 'data.txt', $data );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file test.txt with the following content: text1 text2 And I
I have this test.txt file with the following content: @echo off wget -q http://subs.ro/get/21518
I have a file 4 bytes long called data.txt with following content (four 8
I have a .txt file with the following content: 1 1111 47 2 2222
Lets say I have a text file MyFile.txt with following content: hellosam whatsup mynameisjohn
Suppose I have a foo.txt file with the following content: [2010-11-13 12:00:02,656] [2010-11-13 12:00:02,701]
I have a txt file which contains data in the following format: X1 Y1
I have a file template.txt which contains the following: Hello ${something} I would like
I have the first few lines of a text file fx.txt with the following
I have a C# application that includes the following code: string file = relativePath.txt;

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.