|
użytkowników online: 61
|
OPINIE UŻYTKOWNIKÓW
|
Porady zamieszczone tutaj przez Darka są pomocne w wielu chwilach. Wielokrotnie tworząc jakiś złożony serwis korzystam z tych porad. Można by tworzyć samemu te skrypty, ale tak naprawdę czy nie lepiej jest wziąć skrypt z tej strony i zmodyfikowac go dla swoich potrzeb? Wprawdzie możemy taki skrypt napisać sami, ale po co, skoro stracimy czas na coś, co ktoś juz napisał, przetestował i może zagwarantować, że działa poprawnie. Któryś raz z rzędu opłacam abonament i nie raz jeszcze opłacę. Kawał dobrej roboty i ogrom wiedzy w jednym miejscu.
Piotr Karamański Design Studio
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
convert_cyr_string (PHP 3 >= 3.0.6, PHP 4, PHP 5) convert_cyr_string --
Convert from one Cyrillic character set to another
Descriptionstring convert_cyr_string ( string str, string from, string to )
This function returns the given string converted from one
Cyrillic character set to another. The from
and to arguments are single characters that
represent the source and target Cyrillic character sets. The
supported types are:
k - koi8-r
w - windows-1251
i - iso8859-5
a - x-cp866
d - x-cp866
m - x-mac-cyrillic
Notatka: Ta funkcja jest bezpieczna dla danych
binarnych.
User Contributed NotesTimuretis
06-Nov-2005 03:56
// Modificated by tapin13
// Corrected by Timuretis
// Convert win-1251 to utf-8
function unicode_russian($str) {
$encode = "";
// 1025 = "Ё";
// 1105 = "ё";
for ($ii=0;$ii<strlen($str);$ii++) {
$xchr=substr($str,$ii,1);
if (ord($xchr)>191) {
$xchr=ord($xchr)+848;
$xchr="&#" . $xchr . ";";
}
if(ord($xchr) == 168) {
// $xchr = "Ё";
$xchr = "Ё"; //!!!!!!!!!!!!!!!!!!!!!!!
}
if(ord($xchr) == 184) {
// $xchr = "ё";
$xchr = "ё"; //!!!!!!!!!!!!!!!!!!!!!!
}
$encode=$encode . $xchr;
}
return $encode;
}
tapin13 at atilian dot co dot il
18-Oct-2005 11:20
// Modificated by tapin13
// Convert win-1251 to utf-8
function unicode_russian($str) {
$encode = "";
// 1025 = "Ё";
// 1105 = "ё";
for ($ii=0;$ii<strlen($str);$ii++) {
$xchr=substr($str,$ii,1);
if (ord($xchr)>191) {
$xchr=ord($xchr)+848;
$xchr="&#" . $xchr . ";";
}
if(ord($xchr) == 168) {
$xchr = "Ё";
}
if(ord($xchr) == 184) {
$xchr = "ё";
}
$encode=$encode . $xchr;
}
return $encode;
}
webmaster at chassidus dot ru
30-Aug-2005 07:51
//I've also built the same way for hebrew to utf converting
function heb2utf($s) {
for($i=0, $m=strlen($s); $i<$m; $i++) {
$c=ord($s[$i]);
if ($c<=127) {$t.=chr($c); continue; }
if ($c>=224 ) {$t.=chr(215).chr($c-80); continue; }
}
return $t;
}
//Simple unicoder and decoder for hebrew and russian:
function unicode_hebrew($str) {
for ($ii=0;$ii<strlen($str);$ii++) {
$xchr=substr($str,$ii,1);
if (ord($xchr)>223) {
$xchr=ord($xchr)+1264;
$xchr="&#" . $xchr . ";";
}
$encode=$encode . $xchr;
}
return $encode;
}
function unicode_russian($str) {
for ($ii=0;$ii<strlen($str);$ii++) {
$xchr=substr($str,$ii,1);
if (ord($xchr)>191) {
$xchr=ord($xchr)+848;
$xchr="&#" . $xchr . ";";
}
$encode=$encode . $xchr;
}
return $encode;
}
function decode_unicoded_hebrew($str) {
$decode="";
$ar=split("&#",$str);
foreach ($ar as $value ) {
$in1=strpos($value,";"); //end of code
if ($in1>0) {// unicode
$code=substr($value,0,$in1);
if ($code>=1456 and $code<=1514) { //hebrew
$code=$code-1264;
$xchr=chr($code);
} else { //other unicode
$xchr="&#" . $code . ";";
}
$xchr=$xchr . substr($value,$in1+1);
} else //not unicode
$xchr = $value;
$decode=$decode . $xchr;
}
return $decode;
}
function decode_unicoded_russian($str) {
$decode="";
$ar=split("&#",$str);
foreach ($ar as $value ) {
$in1=strpos($value,";"); //end of code
if ($in1>0) {// unicode
$code=substr($value,0,$in1);
if ($code>=1040 and $code<=1103) {
$code=$code-848;
$xchr=chr($code);
} else {
$xchr="&#" . $code . ";";
}
$xchr=$xchr . substr($value,$in1+1);
} else
$xchr = $value;
$decode=$decode . $xchr;
}
return $decode;
}
cathody at mail dot ru
27-Jul-2005 03:41
Praising other people for their efforts to write a convenient UTF8 to Win-1251 functions may I mention that, since str_replace allows arrays as parameters, the function may be rewritten in a slightly efficient way (moreover, the array generated may be stored for performance improvement):
<?php
function Encode ( $str, $type )
{
static $conv='';
if (!is_array ( $conv ))
{
$conv=array ();
for ( $x=128; $x <=143; $x++ )
{
$conv['utf'][]=chr(209).chr($x);
$conv['win'][]=chr($x+112);
}
for ( $x=144; $x <=191; $x++ )
{
$conv['utf'][]=chr(208).chr($x);
$conv['win'][]=chr($x+48);
}
$conv['utf'][]=chr(208).chr(129);
$conv['win'][]=chr(168);
$conv['utf'][]=chr(209).chr(145);
$conv['win'][]=chr(184);
}
if ( $type=='w' )
return str_replace ( $conv['utf'], $conv['win'], $str );
elseif ( $type=='u' )
return str_replace ( $conv['win'], $conv['utf'], $str );
else
return $str;
}
?>
artyomch at coolfold dot com
26-Apr-2005 10:38
I needed a code for taking UTF8 encoded string from DB and printing it in Win1251 encoded HTML. The problem was that I had to print not just english & cyrillic characters, but all characters stored in UTF encoded string (in my case the DB contained english, russian & hebrew characters).
After reading carefully the UTF8 manual, I've written the following code, that converts all non-win1251 characters into html entities (&#XXXX;).
function utf8_2_win1251 ($str_src)
{
$str_dst = "";
$i = 0;
while ($i<strlen($str_src))
{
$code_dst = 0;
$code_src1 = ord($str_src[$i]);
$i++;
if ($code_src1<=127)
{
$str_dst .= chr($code_src1);
continue;
}
else
if (($code_src1 & 0xE0) == 0xC0)
{
$code_src2 = ord($str_src[$i++]);
if (($code_src2 & 0xC0) != 0x80)
continue;
$code_dst = ( ($code_src1 & 0x1F) << 6) + ($code_src2 & 0x3F);
}
else
if (($code_src1 & 0xF0) == 0xE0)
{
$code_src2 = ord($str_src[$i++]);
if (($code_src2 & 0xC0) != 0x80)
continue;
$code_src3 = ord($str_src[$i++]);
if (($code_src3 & 0xC0) != 0x80)
continue;
$code_dst = ( ($code_src1 & 0x1F) << 12) + ( ($code_src2 & 0x3F) << 6) + ($code_src3 & 0x3F);
}
else
if (($code_src1 & 0xF8) == 0xF0)
{
$code_src2 = ord($str_src[$i++]);
if (($code_src2 & 0xC0) != 0x80)
continue;
$code_src3 = ord($str_src[$i++]);
if (($code_src3 & 0xC0) != 0x80)
continue;
$code_src4 = ord($str_src[$i++]);
if (($code_src4 & 0xC0) != 0x80)
continue;
$code_dst = ( ($code_src1 & 0x1F) << 18) + ( ($code_src2 & 0x3F) << 12) + ( ($code_src3 & 0x3F) << 6) + ($code_src4 & 0x3F);
}
else
{
continue;
}
if ($code_dst)
{
if ($code_dst==0x401)
{
$str_dst .= "
|