Caret, ^together with the dollar sign, $means approving the beginning of the input line and its end if the flag is not set m. You also need to check for spaces at the beginning of a line and matches for lines at the end:
$css_file = preg_replace("/^\s*@import url.*\R*/m", "", $css_file);
^ ^ ^
In case of working with mini CSS:
$css_file = preg_replace("/@import[^;]+;/", "", $css_file);
source
share