Unicode库 Unicode.php
jopen
13年前
<p>Unicode.php 包含一些用于操作 Unicode 数据的 PHP 类和方法。</p> <p>使用示例:</p> <p><code><span style="color:#000000;"><span style="color:#0000bb;"><br /> </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">'Unicode.php'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#0000bb;">$string </span><span style="color:#007700;">= new </span><span style="color:#0000bb;">Unicode_String</span><span style="color:#007700;">();<br /> </span><span style="color:#0000bb;">$string</span><span style="color:#007700;">-></span><span style="color:#0000bb;">fromUTF8</span><span style="color:#007700;">(</span><span style="color:#dd0000;">"Ĥēĺļŏ, Ŵőřļď!"</span><span style="color:#007700;">);<br /> <br /> print </span><span style="color:#dd0000;">"String contains "</span><span style="color:#007700;">.</span><span style="color:#0000bb;">$string</span><span style="color:#007700;">-></span><span style="color:#0000bb;">length</span><span style="color:#007700;">().</span><span style="color:#dd0000;">" characters.\n"</span><span style="color:#007700;">;<br /> <br /> print </span><span style="color:#dd0000;">"String contains characters from the following blocks:"</span><span style="color:#007700;">.</span><span style="color:#0000bb;">implode</span><span style="color:#007700;">(</span><span style="color:#dd0000;">', '</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$string</span><span style="color:#007700;">-></span><span style="color:#0000bb;">blocks</span><span style="color:#007700;">()).</span><span style="color:#dd0000;">"\n"</span><span style="color:#007700;">;<br /> <br /> print </span><span style="color:#dd0000;">"String in UTF-8: "</span><span style="color:#007700;">.</span><span style="color:#0000bb;">$string</span><span style="color:#007700;">-></span><span style="color:#0000bb;">toUTF8</span><span style="color:#007700;">().</span><span style="color:#dd0000;">"\n"</span><span style="color:#007700;">;<br /> <br /> print </span><span style="color:#dd0000;">"String in UPPERCASE: "</span><span style="color:#007700;">.</span><span style="color:#0000bb;">$string</span><span style="color:#007700;">-></span><span style="color:#0000bb;">toUpper</span><span style="color:#007700;">()-></span><span style="color:#0000bb;">toUTF8</span><span style="color:#007700;">().</span><span style="color:#dd0000;">"\n"</span><span style="color:#007700;">;<br /> <br /> </span><span style="color:#0000bb;">$comma </span><span style="color:#007700;">= new </span><span style="color:#0000bb;">Unicode_Character</span><span style="color:#007700;">(</span><span style="color:#0000bb;">ord</span><span style="color:#007700;">(</span><span style="color:#dd0000;">','</span><span style="color:#007700;">));<br /> <br /> </span><span style="color:#0000bb;">$words </span><span style="color:#007700;">= </span><span style="color:#0000bb;">explode</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$comma</span><span style="color:#007700;">);<br /> <br /> foreach (</span><span style="color:#0000bb;">$words </span><span style="color:#007700;">as </span><span style="color:#0000bb;">$word</span><span style="color:#007700;">) {<br /> print </span><span style="color:#dd0000;">"Word has "</span><span style="color:#007700;">.</span><span style="color:#0000bb;">$word</span><span style="color:#007700;">-></span><span style="color:#0000bb;">length</span><span style="color:#007700;">().</span><span style="color:#dd0000;">" characters.\n"</span><span style="color:#007700;">;<br /> }<br /> <br /> </span></span></code></p> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326766035140" target="_blank">http://www.open-open.com/lib/view/home/1326766035140</a></p>