1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
|
==========================================
README for I18N Package
==========================================
o Name and location of package
Name: php-3.0.18-i18n-ja-2
Location: http://www.happysize.co.jp/techie/php-ja-jp/
ftp://ftp.happysize.co.jp/php-ja-jp/
http://php.vdomains.org/
ftp://ftp.vdomains.org/pub/php-ja-jp/
http://php.jpnnet.com/
Currently, this I18N version of PHP only adds Japanese support to base
PHP. It allows you to use Japanese in scripts, as well as conversion
between various Japanese encodings. It will work perfectly fine with
ASCII with i18n option enabled. (note: executable is bit larger due
to UNICODE table). The basic design aproach is to allow for other
languages to be added in the future. Developers are encourage to join
us!
For more information on Japanese encodings, please refer to the
section "Additional Notes."
o What is this package?
This package allows you to handle multiple Japanese encodings (SJIS, EUC,
UTF-8, JIS) in PHP. If you find any bugs in this package, please report
them to the appropriate mailing list. For now, the PHP-jp mailing list
is the best place for this.
PHP-jp ML mailto:PHP-jp@sidecar.ics.es.osaka-u.ac.jp
http://sidecar.ics.es.osaka-u.ac.jp/php-jp/
(discussions are in Japanese)
o Who should use this
Due to lack of documentation, it's not intended for beginners. If
something goes wrong, be prepared to fix it on your own.
o Warranty and Copyright
There is no warranty with this package. Use it at your own risk.
Please refer to the source code for the copyrights. In general, each
program's copyright is owned by the programmer. Unless you obey the
copyright holders restrictions, you are not allowed to use it in any
form.
o Redistribution
As described in the source code, this package and the components are
allowed to be redistributed with certain restrictions.
Due to this package being still in beta, please try to redistribute
it as an entire package. Please try not to distribute it as a form
of patch. Because we would prefer to have this package distributed
as one single package (not patch of patch of patch), avoid releasing
any patch to this package.
o Who made this
A team of volunteers, PHP3 Internationalization, has been contributing
their free time producing it. Although we are not related to the core
PHP programmers, we are hoping to have our modifications merged into the
core distribution in the near future. Thus, we did not call this a
"Japanese Patch" (or distribution). Our final goal is to have true
i18nized PHP!
For anyone interested in this project, please drop us a line.
Contact Address:
phpj-dev@kage.net
(Discussions are in Japanese, but feel free to write us in English)
Webpage (English and Japanese):
http://php.jpnnet.com/
Project Outline (Japanese):
http://www.happysize.co.jp/techie/php-ja-jp/spec.htm
Developers:
Hironori Sato <satoh@jpnnet.com>
Shigeru Kanemoto <sgk@happysize.co.jp>
Tsukada Takuya <tsukada@fminn.nagano.nagano.jp>
U. Kenkichi <kenkichi@axes.co.jp>
Tateyama <tateyan@amy.hi-ho.ne.jp>
Other gracious contributors
o Future plans
- fulfilling what's written in outline
- support for other languages other than Japanese
- make the character conversion as a library (?)
- more testing
o Special Thanks to
PHP Japanese webpage maintainer, Hirokawa-san
http://www.cityfujisawa.ne.jp/%7Elouis/apps/phpfi/
PHP-JP ML's Yamamoto-san
http://sidecar.ics.es.osaka-u.ac.jp/php-jp/
Previous jp-patch developers
==========================================
Advantages of using I18N package
==========================================
- allows you to use various character encodings for script files and
http output
- distinguish character encoding in POST/GET/COOKIE
- proper mail output using JIS as body and MIME/Base64/JIS subject
- if http output's Content-Type is text/html, it will set proper charset
- stable character encoding conversion
- multibyte regex
==========================================
Installation
==========================================
o Summary
Add --enable-i18n option when running configure. For your own setup,
add any other appropriate options as well.
Don't forget to copy php3.ini-dist to desired location.
(ex. /usr/local/lib/php3.ini)
If you have already installed PHP3, copy all the entries in php3.ini-dist
which start with "i18n.xxxx" to php3.ini.
o configure option
--enable-i18n
include i18n features
--enable-mbregex
include multibyte regex library
(without i18n enabled, mbregex functions will not function)
o creating cgi version
% tar xvzf php-3.0.18-i18n-ja-2.tar.gz
% cd php-3.0.18-i18n-ja-2
% ./configure --enable-i18n --enable-mbregex
% make
o creating Apache version (regular module)
% tar xvzf php-3.0.18-i18n-ja-2.tar.gz
% tar xvzf apache_1.3.x.tar.gz
% cd apache_1.3.x
% ./configure
% cd ../php-3.0.18-i18n-ja-2
% ./configure --with-apache=../apache_1.3.x --enable-i18n --enable-mbregex
% make
% make install
% cd ../apache_1.3.x
% ./configure --activate-module=src/modules/php3/libphp3.a
% make
% make install
o creating Apache DSO version
create DSO capable Apache first
% tar xvzf apache_1.3.x.tar.gz
% cd apache-1.3.x
% ./configure --enable-shared=max
% make
% make install
now create php3
% cd php-3.0.18-i18n-ja-2
% ./configure --with-apxs=/usr/local/apache/bin/apxs --enable-i18n \
--enable-mbregex
% make
% make install
==========================================
Additional Notes
==========================================
o Multibyte regex library
From beta4, we have included the multibyte (mb) regex library which comes with
Ruby. With this addition, you can now use regex in EUC, SJIS and UTF-8
encoding. To avoid any conflicts with HSREGEX included with Apache,
each function name has been changed. Therefore, mb regex functions are
named differently from the original ereg functions in PHP. The character
encoding used in mb regex is configured in i18n.internal_encoding.
o Binary Output
If http output encoding is set to other than 'pass', conversion of encoding
from internal encoding to http output is done automatically. Thus,
if you prefer to spit out anything in raw binary format, your data
may be corrupted. In such event, set http_output to 'pass'.
ex.
<?
i18n_http_output("pass");
...
echo $the_binary_data_string;
?>
o Content-Type
Depending on the setting of http_output, PHP will output the proper charset.
ex. Content-Type: text/html; charset="..."
Be aware of following:
- If you set Content-Type header using header() function, that will
override the automatic addition of charset.
- Be cautious when you set i18n_http_output, since if any output is
made prior to this, proper header may have been sent out to the
client already.
o In the event of trouble
If you find any bugs or trouble, please contact us at the above address.
It may help us to track the problem if you send us the script as well.
If you encounter any memory related error such as segmentation violation,
add --enable-debug when you run configure. This will give you more
detail information on where error has occurred. The error is stored
in the server log or regular http output in CGI mode.
o About Japanese encodings
Due to historical reason, there are multiple character encodings used
for Japanese. The most common encodings are: SJIS, EUC, JIS, and UTF-8.
Here are (very) brief description of them:
EUC
commonly used in UNIX environment
8bit-8bit combo
always >=0x80
SJIS
commonly used in Mac or PCs
similar to EUC
mostly 8bit-8bit (some 8bit-7bit)
mostly >=0x80
there are some halfwidth (size of ASCII) multibytes
JIS
commonly used in 7bit environment (nntp and smtp)
starts with escaping char, \033 and a few more characters
UTF-8
16bit+ encoding
defines many languages existing in this world
see http://www.unicode.org/ for more detail
Because of having all these character encodings, PHP needs to translate
between these encodings on the fly. Also, the addition of the mb regex
library allows you to handle mb strings without fear of getting mb char
chopped in half.
Since Japanese is not the only language with multiple encodings, we
encourage other developers to modify our code to suit your needs. We
definitely need people to work with Korean, Chinese (both traditional
and simplified), and Russian. Let us know if you are interested in
this project!
==========================================
php3.ini setting
==========================================
The following init options will allow you to change the default settings.
Define these settings in the global section of php3.ini.
All keywords are case-insensitive.
o Encoding naming
For each encoding, there are three names: standarized, alias, MIME
- UTF-8
standard: UTF-8
alias: N/A
mime: UTF-8
- ASCII
standard: ASCII
alias: N/A
mime: US-ASCII
- Japanese EUC
standard: EUC-JP
alias: EUC, EUC_JP, eucJP, x-euc-jp
mime: EUC-JP
- Shift JIS
standard: SJIS
alias: x-sjis, MS_Kanji
mime: Shift_JIS
- JIS
standard: JIS
alias: N/A
mime: ISO-2022-JP
- Quoted-Printable
standard: Quoted-Printable
alias: qprint
mime: N/A
- BASE64
standard: BASE64
alias: N/A
mime: N/A
- no conversion
standard: pass
alias: none
mime: N/A
- auto encoding detection
standard: auto
alias: unknown
mime: N/A
* N/A - Not Applicapable
o i18n.http_output - default http output encoding
i18n.http_output = EUC-JP|SJIS|JIS|UTF-8|pass
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
pass: no conversion
The default is pass (internal encoding is used)
It can be re-configured on the fly using i18n_http_output().
o i18n.internal_encoding - internal encoding
i18n.internal_encoding = EUC-JP|SJIS|UTF-8
EUC-JP : EUC
SJIS: SJIS
UTF-8: UTF-8
The default is EUC-JP.
PHP parser is designed based on using ISO-8859-1. For other
encodings, following conditions have to be satisfied in order
to use them:
- per byte encoding
- single byte character in range of 00h-7fh which is compatible
with ASCII
- multibyte without 00h-7fh
In case of Japanese, EUC-JP and UTF-8 are the only encoding that
meets this criteria.
If i18n.internal_encoding and i18n.http_output differs, conversion
takes place at the time of output. If you convert any data within
PHP scripts to URL encoding, BASE64 or Quoted-Printable, encoding
stays as defined in i18n.internal_encoding. Thus, if you would
prefer to encode in compliance with i18n.http_output, you need
to manually convert encoding.
ex. $str = urlencode( i18n_convert($str, i18n_http_output()) );
Encoding such as ISO-2022-** and HZ encoding which uses escape
sequences can not be used as internal encoding. If used, they
result in following errors:
- parser pukes funky error
- magic_quotes_*** breaks encoding (SJIS may have similar problem)
- string manipulation and regex will malfunction
o i18n.script_encoding - script encoding
i18n.script_encoding = auto|EUC-JP|SJIS|JIS|UTF-8
auto: automatic
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
The default is auto.
The script's encoding is converted to i18n.internal_encoding before
entering the script parser.
Be aware that auto detection may fail under some conditions.
For best auto detection, add multibyte character at beginning of
script.
o i18n.http_input - handling of http input (GET/POST/COOKIE)
i18n.http_input = pass|auto
auto: auto conversion
pass: no conversion
The default is auto.
If set to pass, no conversion will take place.
If set to auto, it will automatically detect the encoding. If
detection is successful, it will convert to the proper internal
encoding. If not, it will assume the input as defined in
i18n.http_input_default.
o i18n.http_input_default - default http input encoding
i18n.http_input_default = pass|EUC-JP|SJIS|JIS|UTF-8
pass: no conversion
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
The default is pass.
This option is only effective as long as i18n.http_input is set to
auto. If the auto detection fails, this encoding is used as an
assumption to convert the http input to the internal encoding.
If set to pass, no conversion will take place.
o sample settings
1) For most flexibility, we recommend using following example.
i18n.http_output = SJIS
i18n.internal_encoding = EUC-JP
i18n.script_encoding = auto
i18n.http_input = auto
i18n.http_input_default = SJIS
2) To avoid unexpected encoding problems, try these:
i18n.http_output = pass
i18n.internal_encoding = EUC-JP
i18n.script_encoding = pass
i18n.http_input = pass
i18n.http_input_default = pass
==========================================
PHP functions
==========================================
The following describes the additional PHP functions.
All keywords are case-insensitive.
o i18n_http_output(encoding)
o encoding = i18n_http_output()
This will set the http output encoding. Any output following this
function will be controlled by this function. If no argument is given,
the current http output encode setting is returned.
encodings
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
pass: no conversion
NONE is not allowed
o encoding = i18n_internal_encoding()
Returns the current internal encoding as a string.
internal encoding
EUC-JP : EUC
SJIS: SJIS
UTF-8: UTF-8
o encoding = i18n_http_input()
Returns http input encoding.
encodings
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
pass: no conversion (only if i18n.http_input is set to pass)
o string = i18n_convert(string, encoding)
string = i18n_convert(string, encoding, pre-conversion-encoding)
Returns converted string in desired encoding. If
pre-conversion-encoding is not defined, the given
string is assumed to be in internal encoding.
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
pass: no conversion
pre-conversion-encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
pass: no conversion
auto: auto detection
o encoding = i18n_discover_encoding(string)
Encoding of the given string is returned (as a string).
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
ASCII: ASCII (only 09h, 0Ah, 0Dh, 20h-7Eh)
pass: unable to determine (text is too short to determine)
unknown: unknown or possible error
o int = mbstrlen(string)
o int = mbstrlen(string, encoding)
Returns character length of a given string. If no encoding is defined,
the encoding of string is assumed to be the internal encoding.
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
auto: automatic
o int = mbstrpos(string1, string2)
o int = mbstrpos(string1, string2, start)
o int = mbstrpos(string1, string2, start, encoding)
Same as strpos. If no encoding is defined, the encoding of string
is assumed to be the internal encoding.
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
o int = mbstrrpos(string1, string2)
o int = mbstrrpos(string1, string2, encoding)
Same as strrpos. If no encoding is defined, the encoding of string
is assumed to be the internal encoding.
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
o string = mbsubstr(string, position)
o string = mbsubstr(string, position, length)
o string = mbsubstr(string, position, length, encoding)
Same as substr. If no encoding is defined, the encoding of string
is assumed to be the internal encoding.
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
o string = mbstrcut(string, position)
o string = mbstrcut(string, position, length)
o string = mbstrcut(string, position, length, encoding)
Same as subcut. If position is the 2nd byte of a mb character, it will cut
from the first byte of that character. It will cut the string without
chopping a single byte from a mb character. In another words, if you
set length to 5, you will only get two mb characters. If no encoding
is defined, the encoding of string is assumed to be the internal encoding.
encoding
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
o string = i18n_mime_header_encode(string)
MIME encode the string in the format of =?ISO-2022-JP?B?[string]?=.
o string = i18n_mime_header_decode(string)
MIME decodes the string.
o string = i18n_ja_jp_hantozen(string)
o string = i18n_ja_jp_hantozen(string, option)
o string = i18n_ja_jp_hantozen(string, option, encoding)
Conversion between full width character and halfwidth character.
option
The following options are allowed. The default is "KV".
Acronym: FW = fullwidth, HW = halfwidth
"r" : FW alphabet -> HW alphabet
"R" : HW alphabet -> FW alphabet
"n" : FW number -> HW number
"N" : HW number -> FW number
"a" : FW alpha numeric (21h-7Eh) -> HW alpha numeric
"A" : HW alpha numeric (21h-7Eh) -> FW alpha numeric
"k" : FW katakana -> HW katakana
"K" : HW katakana -> FW katakana
"h" : FW hiragana -> HW hiragana
"H" : HW hiragana -> FW katakana
"c" : FW katakana -> FW hiragana
"C" : FW hiragana -> FW katakana
"V" : merge dakuon character. only works with "K" and "H" option
encoding
If no encoding is defined, the encoding of string is assumed to be
the internal encoding.
EUC-JP : EUC
SJIS: SJIS
JIS : JIS
UTF-8: UTF-8
int = mbereg(regex_pattern, string, string)
int = mberegi(regex_pattern, string, string)
mb version of ereg() and eregi()
string = mbereg_replace(regex_pattern, string, string)
string = mberegi_replace(regex_pattern, string, string)
mb version of ereg_replace() and eregi_replace()
string_array = mbsplit(regex, string, limit)
mb version of split()
==========================================
FAQ
==========================================
Here, we have gathered some commonly asked questions on PHP-jp mailing
list.
o To use Japanese in GET method
If you need to assign Japanese text in GET method with argument, such as;
xxxx.php?data=<Japanese text>, use urlencode function in PHP. If not,
text may not be passed onto action php properly.
ex: <a href="hoge.php?data=<? echo urlencode($data) ?>">Link</a>
o When passing data via GET/POST/COOKIE, \ character sneaks in
When using SJIS as internal encoding, or passed-on data includes '"\,
PHP automatically inserts escaping character, \. Set magic_quotes_gpc
in php3.ini from On to Off. An alternative work around to this problem
is to use StripSlashes().
If $quote_str is in SJIS and you would like to extract Japanese text,
use ereg_replace as follows:
ereg_replace(sprintf("([%c-%c%c-%c]\\\\)\\\\",0x81,0x9f,0xe0,0xfc),
"\\1",$quote_str);
This will effectively extract Japanese text out of $quote_str.
o Sometimes, encoding detection fails
If i18n_http_input() returns 'pass', it's likely that PHP failed to
detect whether it's SJIS or EUC. In such case, use <input type=hidden
value="some Japanese text"> to properly detect the incoming text's
encoding.
==========================================
Japanese Manual
==========================================
Translated manual done by "PHP Japanese Manual Project" :
http://www.php.net/manual/ja/manual.php
Starting 3.0.18-i18n-ja, we have removed doc-jp from tarball package.
==========================================
Change Logs
==========================================
o 2000-10-28, Rui Hirokawa <hirokawa@php.net>
This patch is derived from php-3.0.15-i18n-ja as well as php-3.0.16 by
Kuwamura applied to original php-3.0.18. It also includes following fixes:
1) allows you to set charset in mail().
2) fixed mbregex definitions to avoid conflicts with system regex
3) php3.ini-dist now uses PASS for http_output instead of SJIS
o 2000-11-24, Hironori Sato <satoh@yyplanet.com>
Applied above patched and added detection for gdImageStringTTF in configure.
Following setups are known to work:
gd-1.3-6, gd-devel-1.3-6, freetype-1.3.1-5, freetype-devel-1.3.1-5
ImageTTFText($im,$size,$angle,$x1,$y1,$color,"/path/to/font.ttf",
i18n_convert("ܸ", "UTF-8"));
ImageGif($im);
gd-1.7.3-1k1, gd-devel-1.7.3-1k1, freetype-1.3.1-5, freetype-devel-1.3.1-5
ImageTTFText($im,$size,$angle,$x1,$y1,$color,"/path/to/font.ttf","ܸ");
ImagePng($im);
* i18n_internal_encoding = EUC SJIS
For any gd libraries before 1.6.2, you need to use i18n_convert. For
gd-1.5.2/3, upgrade to anything above 1.7 to use ImageTTFText without
using i18n_convert. As long as you have internal_encoding set to EUC or
SJIS, ImageTTFText should work without mojibake. Again, make sure you
have i18n_http_output("pass") before calling ImageGif, ImagePng, ImageJpeg!
o 2000-12-09, Rui Hirokawa <hirokawa@php.net>
Fixed mail() which was causing segmentation fault when header was null.
|