Quick Guide

This quick guide will show you how to use and create it to master and master the tutorial.

Table of Contents

Example

Includes: Provides different ones for you to choose and use.

Example 1: Portable Directory Structure

Run index.php to access the Homepage directory; for other pages, please refer to "Newpage".
Source: latest.zip -> /example/01-directory

Example 2: Standalone version & Portable

Use the array() language structure to build an array and complete all operations through functions; compared to other versions, the portable version is completed by a file.
Source: latest.zip -> /example/02-portable

1. The available language packs are set in advance and are done by query conditions.

$global_lp_all = array('en-us', 'zh-cn', 'zh-tw', 'ja-jp', 'ko-kr', 'ru-ru');

2. Create an array.

$lpna = array (
    'template' => array (
        'en-us' => 'template',
        'zh-cn' => '模板',
        'zh-tw' => '模板',
        'ja-jp' => '模板',
        'ko-kr' => '模板',
        'ru-ru' => '模板'),
    'end' => array (
        'en-us' => 'end',
        'zh-cn' => 'end',
        'zh-tw' => 'end',
        'ja-jp' => 'end',
        'ko-kr' => 'end',
        'ru-ru' => 'end')
);

3. Array calling method.

<?php echo $lpna['lang_page_title'][$lng]; ?>

Please pay attention to the writing of the array when using it, the array demo is only listed in part, please refer to the source code:latest.zip -> /example/02-portable/index.php

      Use the print_r command to output all arrays.

print_r($lpna);

4. Resource conversion.

In the process of using the portable version, such as pictures, ICOs, you need to convert to base64 encoding. Javascript, CSS and other resources are completed with embedded code. Shortening tools can be used.

5. Online conversion website recommendation

Example 3: Database & Array

Connects to SQL database through PDO, and supports MySQL and SQLite. And use the Array function to list all available data.
Source: latest.zip -> /example/03-database

1. Create a database global configuration file.

     Use template latest.zip -> /example/03-database/lp-config.sample.php File, change to new file name: lp-config.php

2. Changing parameters is the same as your server configuration.

define('Database_Mode', '');

define('DB_HOST',       'localhost');

define('DB_NAME',       'lang-php');

define('DB_USER',       'username');

define('DB_PWD',        'password');

define('DB_PREFIX',     'lp_');

define('DB_CHARSET',    'utf8mb4');

3. Dynamic page connection code.

include_once('lp-load.php');

$page_team = 'homepage';

$current_lng = $db->select(DB_PREFIX."translate", "section = '$page_team'");
$lpna = $db->arraymodify($current_lng, $lng);

See latest.zip -> /example/03-database/index.php File.

     Array calling method.

<?php echo $lpna['lang_use_title1']['lp_variable']; ?>

      Use the print_r command to output all arrays.

print_r($current_page);
print_r($lpna);

4. Create new page!

Use template latest.zip -> /example/03-database/templets.php File, the user can change it to the new file name (example: newpage.php).

Modify the current page name for indexing.
$page_team = 'newpage';

Other supplements

Supplement refers to the hidden usage and other functions in use.

Use Javascript(JS) to switch languages and hide parameters

What is Javascript (JS) to switch languages and hide parameters? The purpose is to remove the suffix.
Before using mode 1: https://fengyi.tel/php/?lang=zh-cn;
After using mode 2: https://fengyi.tel/php, the suffix is ​​gone.

1. HTML template.

<html>
<headl>
	<script src="../assets/js/lp.js"></script>
</headl>
<body>
	<a href="?lang=en-us">Switch</a>
</body>
</html>

Source: latest.zip -> /example/*/../assets/js/lp.js

Jump to the specified domain name

What is the jump to the specified domain name? Some examples are by reading and matching the files in the directory. If you want to jump to the specified domain name, please refer to the following code:

Add code to the page you need to jump to!

/* sample 1

header("Location: http://us.fengyi.tel/php");

/* sample 2

public $globalDomain = 'https://fengyi.tel/php/';

function loading($lang)
{
	header("Location:" . $this->globalDomain . $lang);
}

/* sample 3

function loading($lang)
	switch ($lang) {
		case 'zh-cn': header("Location: https://cn.fengyi.tel/php"); break;
		case 'zh-tw': header("Location: https://tw.fengyi.tel/php"); break;
		case 'en-us': header("Location: https://us.fengyi.tel/php"); break;
		case 'ru-ru': header("Location: https://ru.fengyi.tel/php"); break;
		case 'ja-jp': header("Location: https://jp.fengyi.tel/php"); break;
		case 'ko-kr': header("Location: https://kr.fengyi.tel/php"); break;
		default: header("Location: https://global.fengyi.tel/php"); break;
	}
}