Having trouble using FILTER_SANITIZE_NUMBER_INT

Hopefully someone can help. I have a bunch of variables, bu for simplicity’s sake, I’ll just show the one.

[php]<?php
$time = $_GET[“time”].PHP_EOL;

var_dump(filter_var($time, FILTER_SANITIZE_NUMBER_INT));

$file_handle = fopen(“test_file.txt”, “w+”);
$file_contents = $time;

fwrite($file_handle, $file_contents);
fclose($file_handle);
print “File successfully created.”;
?>
[/php]
What is happening is this:

User enters e2!3 in the form.

My screen shows this:

string(2) “23” File successfully created.

The test_file.txt still had e2!3, not the 23 I was expecting/hoping for. Any help?

What happens if you…

Change

[php] $file_contents = $time;[/php]
to

[php] $file_contents = filter_var($time, FILTER_SANITIZE_NUMBER_INT);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service