I create an array with all the date numeric representation of the day (0-6 for sun-sat).
And if it's between 1-5 (mon-fri) add it in the array.
The count of the array is then the number of days without sat-sundays.
<?php
$startdate = '2017-08-04';
$datetime1 = new DateTime($startdate);
$datetime2 = new DateTime('2017-08-07');
$interval = $datetime1->diff($datetime2);
$days = $interval->format('%a');
$arr =array();
for($i=0;$i<=$days;$i++){
$day = date("w Y-m-d l", strtotime($startdate) + $i*86400);
if((int)$day[0] >= 1 && (int)$day[0] <= 5 ) $arr[] = $day;
}
var_dump($arr);
echo "days excluding sat-sundays " . count($arr);
https://3v4l.org/pPLpb
Edit added = to count the end date also.
Edit; there was something not working with my previous strtotime, it gave correct resultat but counted Tuesdays as Mondays.
Changed it to $i*86400 instead and added more data in the array for debugging.