PHP

MULTI-LANGUAGE WEBSITE WITH PHP

<header><?=$_TXT[0]?></header>   <main><?=$_TXT[1]?></main>   <footer><?=$_TXT[2]?></footer>

VARIABLE TEXT PLACEHOLDERS

01

LANGUAGE SWITCHER FORM

02

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

START SESSION session_start();   DEFAULT ENGLISH if (!isset($_SESSION["lang"])) { $_SESSION["lang"] = "en"; }

LANGUAGE SWITCHER PHP

03

CHANGE LANGUAGE if (isset($_POST["lang"])) { $_SESSION["lang"] = $_POST["lang"]; } LOAD LANGUAGE FILE require "lang-" . $_SESSION["lang"] . ".php";

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

LANGUAGE PACKS

04

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