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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:14:07+00:00 2026-05-30T02:14:07+00:00

I have tried to use templates to be able to make a multilingual web

  • 0

I have tried to use templates to be able to make a multilingual web site, so i created a folder called languages containing en.php and fr.php
here is the code for en.php:

<?php
class Index {

    public $filename;
    public $assigned_vars = array();

    public function set($key, $value) {
        $this -> assigned_vars[$key] = $value;
    }

    public function display() {
        if (file_exists($this -> filename)) {
            $output = file_get_contents($this -> filename);
            foreach ($this->assigned_vars as $key => $value) {
                $output = preg_replace('/{' . $key . '}/', $value, $output);
            }
            echo $output;
        } else {
            echo "*** Missing template ***";
        }
    }

}

$index = new Index;
$index -> filename = "templates/index1.php";
$index -> set('page_title', "Welcome");
$index -> set('first_name', "Welcome to our website.");
$index -> display();
?>

and here is the code for fr.php:

<?php
class Index {

    public $filename;
    public $assigned_vars = array();

    public function set($key, $value) {
        $this -> assigned_vars[$key] = $value;
    }

    public function display() {
        if (file_exists($this -> filename)) {
            $output = file_get_contents($this -> filename);
            foreach ($this->assigned_vars as $key => $value) {
                $output = preg_replace('/{' . $key . '}/', $value, $output);
            }
            echo $output;
        } else {
            echo "*** Disparus modèle ***";
        }
    }

}

$index = new Index;
$index -> filename = "templates/index1.php";
$index -> set('page_title', "Bienvenue");
$index -> set('first_name', "Bienvenue sur notre site.");
$index -> display();
?>

then i created a folder called templates and created a file called index1.php

and here is index1.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>{page_title}</title>
    </head>
    <body>
        {first_name}
        <br/>
        <a href="?lang=en-us">english</a>
        <a href ="?lang=fr">French</a><br />
        <?php
        echo strftime("Y", time());
        ?>
    </body>
</html>

and then i created the regular index.php
and here is the code for index.php:

<?php
if (isset($_GET['lang'])) {
    setcookie('language_test', $_GET['lang'], time() + (60 * 60 * 24 * 7));
    if ($_GET['lang'] == "fr") {
        require ('languages/fr.php');
    } else {
        require ('languages/en.php');
    }
} else {
    require ('languages/en.php');
}
?>

here is my problem when i try to show index.php in my browser it works fine but the php code in index1.php doesn’t show any of this strftime();, but when i try to view the source of this
index.php
it’s showing me this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Welcome</title>
    </head>
    <body>
        Welcome to our website.
        <br/>
        <a href="?lang=en-us">english</a>

        <a href ="?lang=fr">French</a><br />
        <?php
        echo strftime("Y", time());
        ?>
    </body>
</html>

thanks in advance. and sorry for being so long and sorry for my awful english.

  • 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-30T02:14:08+00:00Added an answer on May 30, 2026 at 2:14 am

    When you are invoking file_get_contents($this -> filename); it just converts strftime("Y", time()); part as string. So it does not execute.

    In the index1.php you should use {time} instead of

    <?php
    echo strftime("Y", time());
    ?>
    

    So It’ll look like

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>{page_title}</title>
    </head>
    <body>
        {first_name}
        <br/>
        <a href="?lang=en-us">english</a>
        <a href ="?lang=fr">French</a><br />
        {time}
    </body>
    

    Now add time in en.php or fr.php like bellow

    $index -> set('time', strftime("%Y", time()));
    

    Its better not to re-invent a template library. There are plenty available. See this blog post top 25 php template engines

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

Sidebar

Related Questions

I have tried to use stripersist with mysql but was not successful. I have
I have tried to use ASP.NET MVC for a while, then I face a
I have tried to use some of the widgets in JQuery UI on an
I have tried to use mysql fulltext search in my intranet. I wanted to
I have tried to use the following snippet of code: int main() { string
I have heard about JNI and have tried to use it. What I would
Have you tried to use SharePoint with version control such as Perforce (or Subversion),
when i tried to use symfony2 doctrine reverse engineering tools, I have a one
What should i use to code Classic ASP under Linux. I have really tried
I have small library i want to use for creating games. First, i tried

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.