Home >Backend Development >PHP Tutorial >Questions about font application in PHP_PHP tutorial

Questions about font application in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:58:54897browse

Overview: Many friends are confused that the website provides both traditional and simplified versions. How is this achieved? This is also a very important knowledge point that is missed in many PHP books nowadays. The author collected and compiled and listed some key points and doubts based on his own development experience to share with you!

How to use the PHP function to convert Traditional Chinese to Simplified Chinese
We define a big5togb function to achieve this conversion:

function big5togb($code)
{
//The parameter $code is a string of big5 code
include "data_big5.php"; //File containing big5 data
$output="";
$length=strlen($code); //Get the string length
$code=strtok($code,"");
$idx=0;
while ($idx < $length)
{
$tmpStr=$code[$idx].$code[$idx 1];

if (isbig5($tmpStr)) //Determine whether big5 code
{
...//If it is big5 code, convert it and output it
}
else
{
$output.= $code[$idx]; //If it is not a big5 code, output directly
}
$idx ;
}
return ($output);
}

How to use the PHP function to convert Simplified Chinese to Traditional Chinese?

How to convert Simplified Chinese to Traditional Chinese using PHP?

We define a big5togb function to achieve this conversion:

function gbtobig5($code)
{
include "data_gb.php"; //Contains data files with gb code
$output="";
$length=strlen($code);
$code=strtok($code,"");
$idx=0;
while ($idx < $length)
{
$tmpStr=$code[$idx].$code[$idx 1];

if (isgb($tmpStr)) //Determine whether it is gb code
{
...//If it is gb code conversion, output
}
else
{
$output.= $code[$idx]; //If it is not a gb code, output it directly
}
$idx ;
}
return ($output);
}
How to apply PHP output control function in Simplified and Traditional Chinese conversion?

What is the PHP output control function?

PHP's output information control function allows you to control the content output by your script and can be used in many different situations, especially when you need to send a file header after your script has output information and when you need to edit the output information. place. The output control function does not affect the file header information sent using header() or setcookie(), only those data blocks similar to echo(), print() and PHP code.

Example 1. Control output

test.php
function test($str){
return str_replace("world","php",$str);
}
ob_start("test");
echo "hello world";
ob_end_flush();
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631965.htmlTechArticleOverview: Many friends are confused that the website provides both traditional and simplified versions. How is it achieved? This is also a very important knowledge point that is missed in many PHP books nowadays. The author...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn