php if expression using regex

im trying to get any input-ed data to be replaced by the value ‘7’, if it is not a number between 0 and 9.

Here’s my code atm:

echo "Enter no. of days to search: ";
$handle = fopen ("php://stdin","r");
$days = fgets($handle);

$days2 = str_replace("\n", '', $days);

if ($days2 == '/^[0-9]{1}$/'){
    $days2 = "7";}

it doesnt replace any input (letters or numbers) with 7 though!
Help please!
Thanks

Edit:

if ($days2 >= 0 && $days2 <= 9){
    }
else $days2 = "7";

works but only for numbers outside the range, not for if i input letters

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s