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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:30:53+00:00 2026-06-05T12:30:53+00:00

Basically my question is How do you get the value of a variable inside

  • 0

Basically my question is How do you get the value of a variable inside a js file.

E.g

var now = (new Date() - 0);

other_var = 'Whats up';//how to pull the value of the other_var which is 'Whats Up'

key.embed();

How do get the value of the other_var using php? I only need the value of the variable which is ‘whats up’.

Made some digging on my own, now I am able to get the content of the js file using file_get_content function in php, just don’t know how to pull get the variable and pull its value.

  • 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-05T12:30:55+00:00Added an answer on June 5, 2026 at 12:30 pm
    <?php
    
      $file = file_get_contents('myfile.js');
    
      $varNameToFind = 'other_var';
    
      $expr = '/^\s*(?:var)?\s*'.$varNameToFind.'\s*=\s*([\'"])(.*?)\1\s*;?/m';
    
      if (preg_match($expr, $file, $matches)) {
        echo "I found it: $matches[2]";
      } else {
        echo "I couldn't find it";
      }
    

    Example

    Something like that? Note that it would only find string values as it looks for quotes, and there are various holes in it that allow it to match a few things that are syntactically invalid Javascript and it will fall down when there are escaped quotes in the string – but as long as the JS is valid, that should find the first place in the file where a string value is assigned to the named variable, with or without a var keyword.

    EDIT

    A much better version that only matches syntactically valid Javascript strings and should match any valid single strings including those with escaped quotes, although it still won’t handle concatenation expressions. It also gets the actual value of the string as it would be when loaded into Javascript – i.e. it interpolates escape sequences as defined here.

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

Sidebar

Related Questions

Basically my question is i have a website which was developed around 3 years
Basically my question is the exact same one as this: Simple client/server, TCP/IP encrypting
Basically the question could more probably be more accurately asked, how do I simply
Basically the question is, Why are NONE of the changes I've been making in
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
This is basically the same question as Click items in select box, and then
Basically this is a question how to access local scope handler. I trying to
I basically have the same question as this guy .. The example in the
Basically, the question is: Do the Exceptions in C# affect the performance a lot?
Basically, this question with a difference... Is it possible to capture print output from

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.