Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-28-2004, 02:50 PM what am i missing
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
Heeyz need a bit of help

got these 2 codings


PHP Code:
$score "21700";
$scorepre $score*2;
echo 
$scorepre "<br>";
for(
$c=0;$c<strlen($scorepre);$c++) {
@
$realscorecheck+=$scorepre{$c}*($c+1);
@
$realscorecheck-="1";
}
echo 
$realscorecheck

PHP Code:
$score "43400";
$scorepre $score;
echo 
$scorepre "<br>";
for(
$c=0;$c<strlen($scorepre);$c++) {
@
$realscorecheck+=$scorepre{$c}*($c+1);
@
$realscorecheck-="1";
}
echo 
$realscorecheck


the first one returns -5
And the second one 17
Don't get it why are they different? I've been looking at this for a while but don't see anything.

Must be something i'm overlooking
Hope you see it..


Greetz
Thierry
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-28-2004, 06:14 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
First of all, you should not be trying to multiply a string times two. If you want $score to be a number, don't use quotes. I honestly can't tell you what happens when you multiply a string.
PHP Code:
$score 21700;
$scorepre $score 2
Secondly, don't try to check the length of a number. If $scorepre is a number, then cast it back to a string before you check it's length (as you do in the for loop definition).
PHP Code:
for($c=0;$c<strlen( (string) $scorepre);$c++) 
Lastly, I have no idea what this code is even supposed to be doing:
PHP Code:
$realscorecheck+=$scorepre{$c}*($c+1
What are you trying to do here? What effect will $scorepre{$c} have? Can you tell us what you are trying to compute?
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 09-29-2004, 09:22 AM
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
well it's used for protecting my highscore list.
My flash program creates a checksum for the score.
And then the php should create a checksum and see if it matches the flash checksum.

Code looks like this

[PHP]$score = "21700";
$scorepre = $score*2;
echo $scorepre . "<br>";
for($c=0;$c<strlen($scorepre);$c++) {
@$realscorecheck+=$scorepre{$c}*($c+1);
@$realscorecheck-="1";
}
echo $realscorecheck;PHP] ///-5

PHP Code:
$score "43400";
$scorepre $score;
echo 
$scorepre "<br>";
for(
$c=0;$c<strlen($scorepre);$c++) {
@
$realscorecheck+=$scorepre{$c}*($c+1);
@
$realscorecheck-="1";
}
echo 
$realscorecheck
///17


What i want to do is take each character in $scorepre and multiply the first one with 1 the second character with 2 the third one with 3 and so on. Then take 1 of per character.
And then ad all those results together.

Example:
43400 gives
(4*1-1)+(3*2-1)+(4*3-1)+(0*4-1)+(0*5-1)
3+5+11-1-1=17

The problem is i need to get the score and multiply it before doing above.
And for some reason 43400 gives the right number (17)
And 2*21700 gives -5
__________________
Know what to Download

Please login or register to view this content. Registration is FREE

Last edited by lajkonik86; 09-29-2004 at 09:32 AM..
lajkonik86 is offline
Reply With Quote
View Public Profile
 
Old 09-30-2004, 11:46 AM
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
hmmz anybody???
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
Old 10-02-2004, 03:18 PM
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
well i finaly figured it out.
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to what am i missing
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22427 seconds with 12 queries