PHP

MULTI-LANGUAGE WEBSITE WITH PHP

(a quick example)

REPLACE CONTENT WITH PHP VARIABLE <header><?=$_TXT[0]?></header>  <main><?=$_TXT[1]?></main>  <footer><?=$_TXT[2]?></footer>

HTML PAGE LAYOUT

01

LANGUAGE SWITCHER <form method="post">   <input type="submit" name="lang"   value="en">   <input type="submit" name="lang"    value="zh">  </form>

PHP LANGUAGE MANAGER

02

SET SELECTED LANGUAGE IN SESSION session_start(); if (!isset($_SESSION["lang"]))   { $_SESSION["lang"] = "en"; } if (isset($_POST["lang"]))   { $_SESSION["lang"] = $_POST["lang"]; }

LOAD LANGUAGE FILE require "lang-" . $_SESSION["lang"] . ".php";

ENGLISH (LANG-EN.PHP) $_TXT = [   "Site", "Welcome To Site", "Copyright" ];

LANGUAGE PACKS

03

CHINESE (LANG-ZH.PHP) $_TXT = [   "网站", "欢迎来到网站", "版权所有" ];