Jump to content

Recommended Posts

Hi everybody, a few dasy ago i found a function which translates integers into text like this:

 

echo $number->written_number(101); // one hundred one

 

but i've got a problem, this function works fine on russian language, but that this function translate in 3 languages:

russian, english and ukrainian like this:

 

echo $number->written_number(101); // сто один - one hundred one - сто один

 

how can i add english and ukrainian languages?

 

When i tried to add this manually, it was okay but in one moment i received error, and all my script is broked, and now i don't know what to do, i've got a few hours to complete this test work, but unfortunately i've got no idea how to do this(

 

Pls help me somebody, i will infinitely grateful!!!

 

This is my code

<?php
require_once('languages.php');

class numberTransfer extends languages
{
	public function written_number($i, $female = false) {
	
	  if (($i < 0) || ($i >= 1e9) || !is_int($i)) {
	    return false; // Аргумент должен быть неотрицательным целым числом, не превышающим 1 миллион
	  }
	  if($i == 0) {
	    return $this->N0. '</br>' .$this->N0eng;
	  }
	  else {
	    return preg_replace(
	    		array('/s+/','/\s$/'),
                 array(' ',''),
                 $this->num1e9($i, $female)
		 );
	    return $this->num1e9($i, $female);
	  }
	}
	
	public function num_125($n) {
	  /* форма склонения слова, существительное с числительным склоняется
	   одним из трех способов: 1 миллион, 2 миллиона, 5 миллионов */
	  $n100 = $n % 100;
	  $n10 = $n % 10;
	  if(($n100 > 10) && ($n100 < 20)) {
	    return 5;
	  }
	  elseif($n10 == 1) {
	    return 1;
	  }
	  elseif(($n10 >= 2) && ($n10 <= 4)) {
	    return 2;
	  }
	  else {
	    return 5;
	  }
	}
	
	public function num1e9($i, $female) {
	  
	  if($i < 1e6) {
	    return $this->num1e6($i, $female);
	  }
	  else {
	    return $this->num1000(intval($i/1e6), false) . ' ' .
	      $this->Ne6[$this->num_125(intval($i/1e6))] . ' ' . $this->num1e6($i % 1e6, $female);
	  }
	}
	
	public function num1e6($i, $female) {
	  
	  if($i < 1000) {
	    return $this->num1000($i, $female);
	  }
	  else {
	    return $this->num1000(intval($i / 1000), true) . ' ' .
	      $this->Ne3[$this->num_125(intval($i/1000))] . ' ' . $this->num1000($i % 1000, $female);
	  }
	}
	
	public function num1000($i, $female) {
	  
	  if($i < 100) {
	    return $this->num100($i, $female);
	  }
	  else {
	    return $this->Ne2[intval($i/100)] . (($i % 100)?(' '. $this->num100($i % 100, $female)):'').
		'</br>' .$this->Ne2eng[intval($i/100)]. (($i % 100)?(''. $this->num100($i % 100, $female)):'')  ;
	  }
	}
	
	public function num100($i, $female) { 
	  
	  $gender = $female?1:0;
	  if ($i < 20) {
	    return $this->Ne0[$gender][$i]. '</br>' .$this->Ne0eng[$gender][$i];
	  }
	  else {
	    return $this->Ne1[intval($i / 10)] . (($i % 10)?(' ' . $this->Ne0[$gender][$i % 10]):'').
	    '</br>' . $this->Ne1eng[intval($i / 10)] . (($i % 10)?(' ' . $this->Ne0eng[$gender][$i % 10]):'');
	  }
	}
}

$number = new numberTransfer();
echo $number->written_number(101);


as you can see i tried to glue array with russian language words with array with english laguage words.

 

Probably i've got somethink like this:

 

$number = new numberTransfer();
echo $number->written_number(101);

сто один
one
one hundredодин
one

damn bullshit...

Please people help me:)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.