Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FILTER_SANITIZE_NUMBER_INT does not convert string to int

Tags:

php

get

I thought that the filter_input(type, name, FILTER_SANITIZE_NUMBER_INT) will convert the string to int but it seems it does not.

$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

if (isset($id) && is_int($id))

Is there another clean but working way to do this?

like image 560
Chazy Chaz Avatar asked Jan 19 '26 15:01

Chazy Chaz


1 Answers

You can always just cast it:

$id = (int) $_GET['id'];
like image 145
wogsland Avatar answered Jan 21 '26 06:01

wogsland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!