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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:24:06+00:00 2026-05-13T10:24:06+00:00

I’m just about ready to cry. I have read the php.net manual page, tried

  • 0

I’m just about ready to cry. I have read the php.net manual page, tried a dozen Google searches with various phrases, and scanned hundreds of stackoverflow threads. I have seen this method in use, but it just doesn’t work for me. It seems so basic. I have a couple related questions or problems I don’t know how to find answers to.

The important part of the PHP file looks like this:

switch() {
…other cases…
default:
  $tpl['title'] = "Newsletter Signup";
  $tpl['description'] = "Newsletter description";
  $tpl['page-content'] = file_get_contents('signup.html');
}

$tpl_src = addslashes(file_get_contents('index.tpl'));
eval("\$html = \"$tpl_src\";");
echo $html;

My index.tpl file includes lines like these:

<title>{$tpl['title']}</title>
<meta name="description" content="{$tpl['description']}" />
nav, etc…
<div id="main-content"> {$tpl['page-content']} </div>

I like how neat and clean the code is, without a whole bunch of extra <?=…?>‘s.

First, when curly brackets {} appear in a string, what is that called? I might be able to look it up and learn how to use them if I knew.

Next, this just doesn’t work at all. If I remove the single quotes from the variable keys, it’s good, but php.net says you should never do that in case my name becomes a language constant at some point. Fair enough. But how do I fix this? I like using an array for the vars in case I want to build an evalTemplate subroutine and can just pass $tpl to it.

Lastly, $tpl[‘page-content’] doesn’t print out. The variable is set okay; I can use echo $tpl['page-content'] to test, but it appears as a single blank line in the final HTML.

I’m sure there’s just some aspect of the language I don’t know yet. Any help is much appreciated!!

  • 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-13T10:24:07+00:00Added an answer on May 13, 2026 at 10:24 am

    As Volker pointed out, addslashes seems to be an issue. Try addcslashes instead. Also, I’d strongly recommend making this a function, to simplify sanitisation / parsing:

    function render ($file, $vars)
    {
        // .. extra sanitisation, validation, et al.
        $_html = '';
        $_raw_file = addcslashes (file_get_contents ($file), '"\\');
        extract ($vars, EXTR_SKIP);
        eval ('$_html = "'.$_raw_file.'"');
    
        return $_html;
    }
    

    And called thus:

    switch() {
    // …other cases…
    default:
      $tpl['title'] = "Newsletter Signup";
      $tpl['description'] = "Newsletter description";
      $tpl['page-content'] = render ('signup.html');
    }
    
    echo render ('index.tpl', $tpl);
    

    PS: The use of extract above means that your vars will simply be $title, not $tpl['title'], etc.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.