- substr: documentation ( source)
<?
function persian($word)
{
$prefix_list=array('na','bi','be','sər');
$prefix_count=count($prefix_list);
$dictionary=array
(
'mərd'=>'man',
'kar'=>'work',
'çarə'=>'solution'
);
for($index=0;$index<$prefix_count;$index++) //4
{
$prefix=$prefix_list[$index];
$prefix_length=strlen($prefix); //2 2 2 3
$word_prefix=substr($word,0,$prefix_length); //namerd - na
if($word_prefix==$prefix)
{
$root=substr($word,$prefix_length); //namerd, 2 2 2 3
return $root;
}
}
}
$word='namərd';
//$word='bekar';
//$word='biçarə';
//$word='sərbəst';
#1. koku 2. tercume
persian($word);
echo 'salam';
?>