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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:40:08+00:00 2026-06-05T17:40:08+00:00

Basically I want to read and write to a file then save all the

  • 0

Basically I want to read and write to a file then save all the compiled content another file.

Steps:

  1. Say I have a file mycode.js with this code:

      var url = '';     //this will be field throug form in php
    
  2. Now in php, I will input a value of that url e.g www.google.com

  3. How will I be able to append the url I just entered to my js file?
    Expected output:

    var url = 'www.google.com';
    
  4. Also follow question, upon successful append of the value to my JS file I will now create a new file (newlyappend.js), like a save as thing. Where the content of the file is the newly append code:

    var url = 'www.google.com';
    

Would like to achieve this using php.

  • 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-05T17:40:10+00:00Added an answer on June 5, 2026 at 5:40 pm

    Get the .js file content as a string:

    $js = file_get_contents( '/path/to/file/mycode.js' );
    

    $js will now hold the content of the file.

    Replace the empty variable line with a value assignment:

    $url = 'www.google.com';
    $js = str_replace( "var url = '';", "var url = '$url';", $js );
    

    Write the new content back to a new js file:

    file_put_contents( '/path/to/file/newlyappend.js', $js );
    

    Make sure you have proper permissions to read & write files from the specified paths.

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

Sidebar

Related Questions

I have successfully written a vhdl code to read and write a file. Basically
Basically I want to loop through existing arrtickers to get each symbol Then read
Basically, i want to read highscores from a file and check if the user
I'm completely out of ideas right now. Basically, I want to read parts of
This is a code snippet but basically what I want to do is read
I'm implementing a file system. Folders each have an ACL, which will basically just
i have written module which reads and write on /proc file and is working
I have a text file which has first line as below: j0W82LBrSdUbw Basically it
I have a relatively simple case. I basically want to store data about links
I have a file with the following content with some characters are UTF-8 hex

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.