Help me...

2003-09-07 Thread Mohsen Pahlevanzadeh
Hi dears.
Mr.Tavakkolian was helping me until my function completed.
This function converts utf8(digit) to integer.
$farsi_table_linux=array(NONE,
#1776;,
#1777;,
#1778;,
#1779;,
#1780;,
#1781;,
#1782;,
#1783;,
#1784;,
#1785;);
function search_index_array($str)
{
 global $farsi_table;
 
 for ($i=0;$i11;$i++) 
 { 
  if ($farsi_table[$i]==$str ) 
   return $i; 
 } 
 return FALSE;
}// end of search_index_array

function utf8_to_int($str)
{
 $len=strlen($str);
 $out=;
 $char=explode(;,$str);
 for ($i=0;$i$len;$i++)
  { 
   $char[$i].=;;
   if (search_index_array($char[$i])!=False)
 $out.=search_index_array($char[$i])-1;
  }//end of for ($i)
 return $out; 
}//end of utf8_to_int
When i call utf8_to_int(#1776;.#1785;) ,this return 09 ,But When i enter a 
number(utf8) via keyboard,This function return 0.
Please guide me that i how enter a number via keyboard(persian)  i get true answer.
--regards

_
Thank you for choosing LinuxQuestions.
http://www.linuxquestions.org
___
FarsiWeb mailing list
[EMAIL PROTECTED]
http://lists.sharif.edu/mailman/listinfo/farsiweb


Re: Help me...

2003-09-07 Thread Skip Tavakkolian
Hi,

As I mentioned in my original posting, I am not a PHP programmer; But,
it seems that for keyboard input functions you WILL have to convert
UTF-8 to HTML encoding if you want to use your function; for example
by calling a function like htmlentities()  or utf8_decode() before
calling utf8_to_int().  The pseudo code looks like this:

if (input is in UTF-8) {# for example input is from a Linux keyboard
$str = htmlentities($str, ENT_COMPAT, UTF-8 );
}
$intvalue = utf8_ot_int($str);

I've included the function again; I added the extra code to check for x in set y
test.  Also note the use of the built-in strtr() function.  These builtins usually
are more efficient (written in C) and are faster.   This code has not been tested.

function utf8_to_int($str)
{
$transtbl = array (
#1776; = '0',
#1777; = '1',
#1778; = '2',
#1779; = '3',
#1780; = '4',
#1781; = '5',
#1782; = '6',
#1783; = '7',
#1784; = '8',
#1785; = '9'
);

foreach ($transtbl as $key = $value) {
if ($key == $str) { # it has an HTML 
encoded numeric
$str = strtr($str, $transtbl);  # convert all of them to ASCII 
[0-9]
return (int) $str;  # convert to whole 
thing to integer
}
}
return (int) $str;
}

One last thing, this function (and your version) has a fatal flaw. Do you
want to guess what it is? 

Hint:  What happens if the string is ABCDE?  What is the difference in the
return value from the function for the strings  ABCD and #1776;?

-Fariborz
---BeginMessage---
Hi dears.
Mr.Tavakkolian was helping me until my function completed.
This function converts utf8(digit) to integer.
$farsi_table_linux=array(NONE,
#1776;,
#1777;,
#1778;,
#1779;,
#1780;,
#1781;,
#1782;,
#1783;,
#1784;,
#1785;);
function search_index_array($str)
{
 global $farsi_table;
 
 for ($i=0;$i11;$i++) 
 { 
  if ($farsi_table[$i]==$str ) 
   return $i; 
 } 
 return FALSE;
}// end of search_index_array

function utf8_to_int($str)
{
 $len=strlen($str);
 $out=;
 $char=explode(;,$str);
 for ($i=0;$i$len;$i++)
  { 
   $char[$i].=;;
   if (search_index_array($char[$i])!=False)
 $out.=search_index_array($char[$i])-1;
  }//end of for ($i)
 return $out; 
}//end of utf8_to_int
When i call utf8_to_int(#1776;.#1785;) ,this return 09 ,But When i enter a 
number(utf8) via keyboard,This function return 0.
Please guide me that i how enter a number via keyboard(persian)  i get true answer.
--regards

_
Thank you for choosing LinuxQuestions.
http://www.linuxquestions.org
___
FarsiWeb mailing list
[EMAIL PROTECTED]
http://lists.sharif.edu/mailman/listinfo/farsiweb
---End Message---
___
FarsiWeb mailing list
[EMAIL PROTECTED]
http://lists.sharif.edu/mailman/listinfo/farsiweb