Somehow I doubt that PHP should have access to that file on a live environment, but anyway you'd need to use regular expression to get at the contents:
$directories = preg_match_all("/(<Directory[^>].*?>.*?<\\/Directory>)/si", $httpd_contents, $matches);
$matches should contain all <Directory> directives. You could then split each on \n to edit each line.