English
Main Menu
My panel

  • Welcome to The Ultimate Site of Worms Armageddon. Please log in or sign up.
Active chat preview

This box automatically views your last visited chat.

PHP expert needed!

Started by Ray, February 29, 2012, 03:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ray


MonkeyIsland

Damn wanted to play good cop bad cop with statk again. :/
Due to massive misunderstandings: MonkeyIsland refers to an island not a monkey. I would be a monkey, if my name was IslandMonkey meaning a monkey who is or lives on an island. MonkeyIsland is an island which is related to monkeys. Also there's been a legend around saying MonkeyIsland is a game. So please, think of me as an island or a game.

Rok

Finaly something from Statik that Ray was happy with! :)

Oh btw, we need a PHP forum. Make Ray the moderator.
chakkman> if rok was a girl i d marry the bitch lolz

Statik



dt`wreckz: zooks are effected my win

Ray

I'm always happy that Statik helps me, I think we just suffer from that "neither of us are native English speakers" issue, so we never understand what the other really means.

That might be just my poor explanation and phrasing though.

avirex

Lolyou guys both speak excellent english... Sometimes I wonder if statik is to pro for you ray?  Im mega newb,so I have no idea.. Just seems like statik always has an answer, and he seems leet :D

Ray

#51
I am completely clueless over validating 0 as integer. I am trying to validate user input in the range of 0 to 2. The user input is given to a function like this:

(int)mysql_real_escape_string(filter_var(trim($_POST['score']), FILTER_SANITIZE_NUMBER_INT))

Now inside the function, I even checked it to be exactly 0 like this:

if ($score === 0) echo 'something';

That worked. However... in the validation process, it's not working, probably because the FILTER_VALIDATE_INT filter does not validate 0 as an integer, even though I did everything for it to accept it as an integer. Values 1 and 2 are accepted by this:

filter_var($score, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'max_range'=> 2 )))

Anyone can tell me why this validation fails for the value 0?

EDIT: found out 0 is handled as empty for some reason. :-X

Quote from: avirex on May 16, 2012, 10:21 AM
Lolyou guys both speak excellent english... Sometimes I wonder if statik is to pro for you ray?  Im mega newb,so I have no idea.. Just seems like statik always has an answer, and he seems leet :D
I'm far away from excellent English, but thank you, that feels nice from a native speaker. :-[ Yes, Statik always has an answer and he is a great coder, no doubt about that, I'm just usually looking for something else, not what he thinks and I meant that if I was Russian and I could ask him in our native language, he would give me the exact answer I'm looking for. :)

Crazy


MonkeyIsland

Why so much trouble for a range Ray?


if (in_array(trim($_POST['score']), range(0, 2)))
   //do stuff.
Due to massive misunderstandings: MonkeyIsland refers to an island not a monkey. I would be a monkey, if my name was IslandMonkey meaning a monkey who is or lives on an island. MonkeyIsland is an island which is related to monkeys. Also there's been a legend around saying MonkeyIsland is a game. So please, think of me as an island or a game.

Statik

Hey MI, you are wrong (!), try to set $_POST['score'] to "2a", "a2", "bbb", etc. ;)

For Ray (less words, more links!):

http://php.net/manual/en/function.filter-var.php (NOTE: Returns the filtered data, or FALSE if the filter fails.)

Solution: http://www.cleancode.co.nz/blog/664/filter_validate_int-0


dt`wreckz: zooks are effected my win

Statik

Wasn't sure if I should write this... but simple regular expression is shorter and cleaner way to validate integer:


if (preg_match('/^[0-2]$/', $score))
    ...


:)


dt`wreckz: zooks are effected my win

Tomi

[OFF]
Interesting theme :D

Btw don't we have a C/C++ topic? Because I need help in Visual C++ xD
[/OFF]

Btw the website looks cool Ray! ;)

MonkeyIsland

Statik he simply wants to validate the POST data to see whether it is one of the 3 values or not. I highly doubt if he wants to get "2" from "2a".
Due to massive misunderstandings: MonkeyIsland refers to an island not a monkey. I would be a monkey, if my name was IslandMonkey meaning a monkey who is or lives on an island. MonkeyIsland is an island which is related to monkeys. Also there's been a legend around saying MonkeyIsland is a game. So please, think of me as an island or a game.

Statik

Quote from: MonkeyIsland on May 17, 2012, 10:32 AM
Statik he simply wants to validate the POST data to see whether it is one of the 3 values or not. I highly doubt if he wants to get "2" from "2a".

Exactly, but when you use in_array() without the 3rd parameter set to true, the comparison is not strict, it means 2 == '2a' and 0 == 'abbbdd2'. Maybe smth like that will work tho: in_array($_POST['score'], array('0', '1', '2'), true), I didn't check.


dt`wreckz: zooks are effected my win

chakkman

Quote from: Crazy on May 16, 2012, 11:46 PM
Get a life

LOL

No offense, Ray. Was just a funny answer after all that code stuff. :)