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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:02:45+00:00 2026-05-12T18:02:45+00:00

I have PHP variables to place within an included HTML file. What’s the best

  • 0

I have PHP variables to place within an included HTML file. What’s the best way of executing this?

//contents of file1.php
$variable1 = "text 1";
$variable2 = "text 2"
$newContent = include('file2.php');
echo $newContent;

//contents of file2.php
<p>standard HTML with PHP... <strong><?=$variable1?></strong></p>
<p><?=$variable2?></p>

This general method is considered OK but the actual code here doesn’t work. Do I use file_get_contents() or include(), how do I execute the PHP within the includes file to output the correct contents?

Should I be using something like HTML>>>

  • 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-12T18:02:45+00:00Added an answer on May 12, 2026 at 6:02 pm

    What you’re doing is fine, and you’ll find that most people use the same exact method. I personally wouldn’t use PHP short tags (some hosts don’t enable it), but that’s a matter of preference.

    Edit: As per your edit, it seems like you don’t have short tags enabled. Check your ini (http://php.net/manual/en/ini.core.php). But you really shouldn’t be using short tags, because as clownbaby mentions, PHP 6 will deprecate them. Even if you don’t care about future proofing your code, they’re still troublesome (which is evident because your code isn’t working). Switch to <?php echo $variable1; ?> and you’ll be fine.

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

Sidebar

Related Questions

I have a file that defines constant variables, like this: define_vars.php <? define(something,value); define(something1,value);
I have a settings.php file with parametric variables and a functions.php with well, some
I have a function in a functions.php file that defines certain variables: add_action( 'the_post',
Really stumped on this one. I have the following PHP file with a variable
We have FireSymfony that allows one to view the Symfony, PHP variables in a
Does PHP have a method of having auto-generated class variables? I think I've seen
I have certain PHP class methods that access external variables. These variables are not
I'm having trouble with global variables in php. I have a $screen var set
I want to share my session variables in PHP using many subdomains. I have
I have a problem with passing variables as reference in PHP. I want to

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.