By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

reading only the last number from i.e. "1234" (4 that will be)

P: n/a
as 1st, sorry on my clumsy english (now I realy miss some words)

I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:

1 slikU
2 slikE
3 slikE
4 slikE
5 slikA
6 slikA
7 slikA
....
20 slikA
21 slikU
22 slikE
23 slikE
24 slikE
25 sliKA
....
99 slikA
100 slikA
101 slikU
102 slikE...

so that is pattern:
all numbers which ends with 1 need to have "U",
2-4 = "E"
5-x0 = "A"

and question: how to read only the last number from count(*) ?

--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
.oO(JaNE)
I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:
[...]

so that is pattern:
all numbers which ends with 1 need to have "U",
2-4 = "E"
5-x0 = "A"

and question: how to read only the last number from count(*) ?


I would do it differently. The pattern is always the same, so it's quite
easy to just devide the number by 10 and have a look at the remainder
(modulo operation), e.g.

$number = 22;
$foo = array('a', 'u', 'e', 'e', 'e', 'a', 'a', 'a', 'a', 'a');
print $foo[$number % 10];

will print 'e'.

The array $foo contains the chars for 0, 1, 2, ... , 9. The expression

$number % 10

calculates the remainder when deviding the number by 10, which is then
used as an index in the char array.

HTH
Micha
Jul 17 '05 #2

P: n/a
JaNE wrote:
as 1st, sorry on my clumsy english (now I realy miss some words)

I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:

1 slikU
2 slikE
3 slikE
4 slikE
5 slikA
6 slikA
7 slikA
...
20 slikA
21 slikU
22 slikE
23 slikE
24 slikE
25 sliKA
...
99 slikA
100 slikA
101 slikU
102 slikE...

so that is pattern:
all numbers which ends with 1 need to have "U",
2-4 = "E"
5-x0 = "A"

and question: how to read only the last number from count(*) ?

You could also do a typeconversion:

$str = (string) $num;
$lastchar = $str [strlen($str)-1];

followed by an if/else or a switch/case statement, or a lookup using the
reconverted char in a predefined string/array with all the appropriate
characters/strings.

You may omit the explicit conversion, but it is not good coding practice.

Using modulo as offered by others is probably the neater, quicker and
more correct approach I admit. The latter bit (the lookup) can be used
in the modulo approach very well too.

Schraalhans.
Jul 17 '05 #3

P: n/a
"JaNE" <no****@mail.dot> wrote in message
news:1gqjgxv.1jlgn2h13rc8wqN%no****@mail.dot...
as 1st, sorry on my clumsy english (now I realy miss some words)

I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:


Use the % operator to get the remainder after a division:

5 % 10 == 5
15 % 10 == 5
135 % 10 == 5
1234 % 10 == 4

For the word endings, you probably want to write a function since the logic
can get quite complicated. And it's something you'd use often.

An example:

function k($num) {
if($num >= 10 && $num <= 19) {
return 'a';
}
$mod = $num % 10;
if($mod == 1) {
return 'u';
}
else if($mod >= 5) {
return 'a';
}
else {
return 'e';
}
}

I'm guessing here that it's "0 slika" and not "0 sliku".

For those who don't understand what the problem is: the OP wants to print
the correct word ending for a given number of objects. In English, we have
"1 picture" but "2 pictures". In Slavic languages this is much more
complicated. 1 is singular; 2, 3, and 4 are plural; 5 and above need a
different declension (4 pictures, but 5 of pictures). The final digit
determines the ending (24 pictures, 25 of pictures), which is why the
modulus of 10 is taken. The exceptions are 10 - 19.
Jul 17 '05 #4

P: n/a
Chung Leong wrote:
<snip>
I'm guessing here that it's "0 slika" and not "0 sliku".

For those who don't understand what the problem is: the OP wants to print the correct word ending for a given number of objects. In English, we have "1 picture" but "2 pictures". In Slavic languages this is much more
complicated. 1 is singular; 2, 3, and 4 are plural; 5 and above need a different declension (4 pictures, but 5 of pictures). The final digit
determines the ending (24 pictures, 25 of pictures), which is why the
modulus of 10 is taken. The exceptions are 10 - 19.


Oh cool:) Chung knows Croatian too...

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.