Forums
May 29, 2024, 11:04 AM

Author Topic: PHP expert needed!  (Read 5330 times)

0 Members and 1 Guest are viewing this topic.

Offline Ray

Re: PHP expert needed!
« Reply #45 on: May 15, 2012, 05:03 PM »
Cheerz! ;)

Online MonkeyIsland

Re: PHP expert needed!
« Reply #46 on: May 15, 2012, 05:42 PM »
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.

Offline Rok

Re: PHP expert needed!
« Reply #47 on: May 15, 2012, 06:46 PM »
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

Re: PHP expert needed!
« Reply #48 on: May 15, 2012, 06:56 PM »
lol @ PHP forum :D


dt`wreckz: zooks are effected my win

Offline Ray

Re: PHP expert needed!
« Reply #49 on: May 15, 2012, 08:20 PM »
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.

Offline avirex

Re: PHP expert needed!
« Reply #50 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

Offline Ray

Re: PHP expert needed!
« Reply #51 on: May 16, 2012, 10:34 PM »
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:

Code: [Select]
(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:

Code: [Select]
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:

Code: [Select]
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

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. :)
« Last Edit: May 16, 2012, 10:44 PM by Ray »

Offline Crazy

Re: PHP expert needed!
« Reply #52 on: May 16, 2012, 11:46 PM »
Get a life

Online MonkeyIsland

Re: PHP expert needed!
« Reply #53 on: May 17, 2012, 05:53 AM »
Why so much trouble for a range Ray?

Code: [Select]
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.

Re: PHP expert needed!
« Reply #54 on: May 17, 2012, 08:16 AM »
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

Re: PHP expert needed!
« Reply #55 on: May 17, 2012, 08:35 AM »
Wasn't sure if I should write this... but simple regular expression is shorter and cleaner way to validate integer:

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

:)


dt`wreckz: zooks are effected my win

Offline Tomi

Re: PHP expert needed!
« Reply #56 on: May 17, 2012, 10:30 AM »
[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! ;)

Online MonkeyIsland

Re: PHP expert needed!
« Reply #57 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".
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.

Re: PHP expert needed!
« Reply #58 on: May 17, 2012, 10:52 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

Offline chakkman

Re: PHP expert needed!
« Reply #59 on: May 17, 2012, 11:19 AM »
Get a life

LOL

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