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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:34:51+00:00 2026-06-18T16:34:51+00:00

I can return a value from embedded php within the variable (as below), but

  • 0

I can return a value from embedded php within the variable (as below), but in this case I would like to get the output of a php file e.g. result.php.

var jsVar = "<?php echo 'thisisfromphp' ?>";

So running ‘result.php’ would produce a result to be returned. How could I grab this result from result.php and use it as the variable – I was thinking something like:

var jsVar = "<?php echo result.php ?>";

P.S. I would embed the php code from result.php in the variable (as above) but it all gets to messy..

  • 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-18T16:34:52+00:00Added an answer on June 18, 2026 at 4:34 pm

    What you should do is refactor your code. Don’t have result.php echo something out that you try and capture. That’s not resuable code. Abstract whatever it does into a function that can be reused, then you can just require "result.php" and later callYourFunction() to get the desired output.

    If, however, you are insistent on doing it this way (which, again, I advise against), you could:

    ob_start();
    require_once 'result.php';
    $contents = ob_get_contents();
    ob_end_clean();
    
    // later...
    var jsVar = <?php echo json_encode($contents); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to return a value from (transport) to the calling function, but can't
How can I return value from enclosing js function? I've tried next example, but
I have a stored procedure like this: Select @totalMoney*@bonusPercent/100 How i can return value
I have a function from which I would like to return a value as
Possible Duplicate: Can’t get correct return value from an jQuery Ajax call How to
How can I return a value from ShowStatus elapsed event? Here is my code.
How can I get the return value of a process? Basically I'm ** ShellExecute
How can I do this in Moq? Foo bar = new Foo(); Fake(bar.PrivateGetter).Return('whatever value')
I can't get the ObjectId for a model to return back with a value
I can't understend why variable s_return dont work $('.codeinput').change(function() { var s_return=; var to_check=this.value

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.