This won't work (a lot more conditions to check for), but it might (or might not) be a start:
function strip_whitespace_php($file)
{
$tmp = $file;
while ($pos_1 = strpos($tmp, '//')) {
$pos_2 = strpos($tmp, "\n", $pos_1);
$tmp = str_replace(substr($tmp, $pos_1, $pos_2 - $pos_1 + 1), '', $tmp);
}
while ($pos_1 = strpos($tmp, '/*')) {
$pos_2 = strpos($tmp, '*/', $pos_1);
$tmp = str_replace(substr($tmp, $pos_1, $pos_2 - $pos_1 + 1), '', $tmp);
}
$tmp = str_replace(array("\t", "\r", "\n", " "), '*', php_strip_whitespace($tmp));
return $tmp;
}
BTW, "php_strip_whitespace()" doesn't strip all whitespace, at least in v.5.0.4, according to this script:
// PHP comment here
/*
* Another PHP comment
*/
$str = php_strip_whitespace(__FILE__);
echo '<pre>';
echo htmlentities(str_replace(array("\t", "\r", "\n", " "), '*', $str));
echo '</pre>';
// Newlines are considered whitespace, and are removed too: