If you want to quantify the numbers appropriately, I would suggest the following:
<?php
$subject = "This takes between 5 and 7 days";
$dayspattern = '/\d+(\.\d+)? ?days?/';
$hourspattern = '/\d+(\.\d+)? ?hours?/'
$hours = -1;
if (preg_match($dayspattern , $subject, $matches) > 0)
{
preg_match($dayspattern, $matches[0], $days);
$hours = $days * 24;
} elseif (preg_match($dayspattern , $subject, $matches) > 0) {
preg_match($hourspattern, $matches[0], $hours);
$hours = $hours;
}
?>
You would need to consider:
- what happens when no numbers are found, or numbers are given as text instead.
- what happens when someone says '1 day and 5 hours'
Hopefully this gives you enough information to do the rest yourself.