Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

hello PHP developers why code is best....

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

hello PHP developers why code is best....

Postby maxim » Fri Jan 17, 2003 2:37 am

i am have a text in georgian... and need to fly convert to unicode......
need to replase function
I am have a 2 code
code 1
Code: Select all
<?php

$TrailingBytes = array ( 0 =>
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
);



function replace_latin_georgian($text)
{
   $latin_letters = 'abgdevzTiklmnopJrstufqRySCcZwWxjh';
   $georgian_symbols = array(0 => 'ßâÉ','ßâæ','ßâÆ','ßâô','ßâö','ßâò','ßâû',
      'ßâù','ßâÿ','ßâÖ','ßâÜ','ßâ¢','ßâ£','ßâ¥','ßâ&#8359;','ßâƒ','ßâá',
      'ßâí','ßâó','ßâú','ßâñ','ßâÑ','ßâª','ßâº','ßâ¿','ßâ&#8976;','ßâ¬',
      'ßâ½','ßâ¼','ßâ¡','ßâ«','ßâ»','ßâ&#9617;');


global  $TrailingBytes;

$FirstCharPos=0;
$newtext = '';
for($i=0;$i<strlen($text); $i++)
   {
     
     if ($i==$FirstCharPos)
        {
    $chcode=ord($utf8_string{$i});
         $charLength = $TrailingBytes[$chcode]+1;
         $FirstCharPos+= $charLength;
         
         if ($charLength == 1) { //Latin character
      $oneitem = $text{$i};
           $charpos = strpos($latin_letters, $oneitem);
      if (!($charpos===false))
         $newtext .= $georgian_symbols[$charpos];
      else $newtext .= $oneitem;
       
    } else $newtext .= substr($text,$i,$charLength);
        }
   }

if ($i!=$FirstCharPos)
    {
     trigger_error("Incorrect UTF8 string", E_USER_ERROR);
     return NULL;
    }
else return $newtext;

}

?>



code 2
Code: Select all
<?php
/* Copyright (C) 2003 Tim @ <a href="http://www.forum.ge" target="_blank">www.forum.ge</a> . All rights reserved.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
// recoding georgian letters from UTF-8 to Latin;

    function geo2latin($text) {
$ge_ltr=array("&#4304;","&#4305;","&#4306;","&#4307;","&#4308;","&#4309;","&#4310;","&#4311;","&#4312;","&#4313;","&#4314;","&#4315;","&#4316;","&#4317;","&#4318;","&#4319;","&#4320;","&#4321;","&#4322;","&#4323;","&#4324;","&#4325;","&#4326;","&#4327;","&#4328;","&#4329;","&#4330;","&#4331;","&#4332;","&#4333;","&#4334;","&#4335;","&#4336;");
$en_ltr=array("a","b","g","d","e","v","z","T","i","k","l","m","n","o","p","J","r","s","t","u","f","q","R","y","S","C","c","Z","w","W","x","j","h");
        for ($i=0; $i<=33; $i++) {
        $text = str_replace($ge_ltr[$i], $en_ltr[$i], $text);
        }
        return $text;
    }
?>


what of code script(code 1 or code 2) is fast and why is fast please answer me....
need to more then 20000 simbol convert at time....

Thanks:)
maxim
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jan 17, 2003 2:25 am

Re: hello PHP developers why code is best....

Postby WiZARD » Fri Jan 17, 2003 7:01 am

I'm choose second variant, cause it's faster and safed!
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby maxim » Tue Jan 21, 2003 11:00 pm

WIZARD
10x:)
Very much!!
maxim
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jan 17, 2003 2:25 am

Postby WiZARD » Wed Jan 22, 2003 9:10 am

Hi! If you askin why?
Cause in first code in each processing char need load your table, - it's you RAM and speed....
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.