Use of PHP output control functions in simplified and traditional Chinese conversion

Source: Internet
Author: User
Summary: This article briefly introduces the PHP output control function and provides specific ideas and examples for its use in simplified and traditional Chinese conversion. A php output control function first let PHP as one of today's popular scripting languages, with easy to write, performance speed summary: this article briefly introduces the output control function of PHP and provides specific ideas and examples for its use in simplified and traditional Chinese conversion.

   A php output control function first

As one of the popular script languages today, PHP has the advantages of easy writing, fast performance, and good scalability. The PHP output information control function allows you to control the output content of your script, which can be used in many different situations, especially when your script has output information, you need to send the file header and compile and process the output information. The output control function does not affect the header information sent by the application header () or setcookie (). it only applies to data blocks similar to echo (), print (), and PHP code.

Example 1. control output

Test. php

<?
Function test ($ str ){
Return str_replace ('php2000', 'y10k', $ str );
}
Ob_start ('test ');
Echo 'hello php2000 ';
Ob_end_flush ();
?>


This program should output

Hello php2000

However, after the output control function is specified, the output becomes

Hello y10k

In the above example, the output content of the application echo () will be retained in the output buffer until ob_end_flush () is called or the script stops running, then, the output information is processed by the custom processing function (replacing the strings) and the result is returned.

Coherent function clarification:

Ob_start ([string output_callback])-open the output buffer

All output information is not directly sent to the browser, but stored in the output buffer. the optional callback function is used to process output information.

Ob_end_flush-end (SEND) output buffer content, closed output buffer

   Implementation of simplified and traditional Chinese conversion

Generally, it is achieved through the situation of the comparison table. There are a lot of articles related to it. here we will not talk about it a few times, only the modern code is given.

<?
Function gb2big5 ($ str ){
Global $ _ gb_big5 _;
$ Leng = strlen ($ str)-1;
For ($ I = 0; $ I <$ leng; $ I ){
$ H = ord ($ str [$ I]);
If ($ h> = 160 ){
$ L = ord ($ str [$ I 1]);
$ Gb = ($ h = 161 & $ l = 64 )? '': Substr ($ _ gb_big5 _, ($ h-160) * 510 ($ L-1) * 2, 2 );
$ Str [$ I] = $ gb [0];
$ Str [$ I 1] = $ gb [1];
$ I;
}
}
Return $ str;
}
?>


Where:

$ Gb_big5 _ reserved the big5 font table
$ Str is the string to be converted

  Utilization of three output control functions in simplified and traditional Chinese conversion

Currently, most websites use their own simple and traditional pages for conversion. as a result, you need to modify the traditional pages again when correcting the simplified pages, and cannot perform active synchronization. We provide this method to enable the active transformation of the same page to display simplified and traditional Chinese characters. The actual method is:

1. create a simplified and traditional Chinese mark to facilitate the current display of the simplified and traditional Chinese status, and switch between the simplified and traditional Chinese statuses.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.