Answer the question
In order to leave comments, you need to log in
Why does RegExp put Apache2?
To remove multiline comments like /*...*/ I wrote the following regular expression: I /\/\*(.|.*\n){0,}/
tested it on a small example, everything works. But as soon as a large file larger than 300 kb is supplied as input, the server crashes. I can't decide what the problem is. The regular for finding and deleting single-line comments works properly. Here are the regular expressions for single-line comments: /\/{2}[a-zA-Z].*/
/\/{2}\s.*/
Both Denver and Apache fit Ubuntu. What's my mistake?
Here is the full script code:
<?php
function slib_compress_script( $buffer ) {
$buffer = preg_replace("/\/{2}\s.*/", "", $buffer);//однострочные
$buffer = preg_replace("/\/{2}[a-zA-Z].*/", "", $buffer);//однострочные
//$buffer = preg_replace("/\/\*(.|.*\n){0,}/", "", $buffer);//Та самая регулярка на многострочные комментарии
return trim( $buffer );
}
$jsLibsPatch = "libs/";
$jsLibsData = '';
$pattern = '/\/\*[\s\S]*?\*\//';
$folder = scandir($jsLibsPatch);
foreach($folder as $file)
{
if(($file !=".") && ($file !="..")){
$jsFileName = $jsLibsPatch.$file;
$fileHandle = fopen($jsFileName, 'r');
$jsLibsDataNew = fread($fileHandle, filesize($jsFileName));
$jsLibsDataNew = slib_compress_script($jsLibsDataNew);
$jsLibsData .= "\n" . $jsLibsDataNew;
fclose($fileHandle);
}}
$jsPatch = "file/";
$jsData = '';
$folder = scandir($jsPatch);
foreach($folder as $file)
{
if(($file !=".") && ($file !="..")){
$jsFileName = $jsPatch.$file;
$fileHandle = fopen($jsFileName, 'r');
$jsDataNew = fread($fileHandle, filesize($jsFileName));
$jsDataNew = slib_compress_script($jsDataNew);
$jsData .= "\n" . $jsDataNew;
fclose($fileHandle);
}}
header("Content-Type: text/javascript");
if (isset($jsData)) {
//$jsLibsData = preg_replace('/\s+/', ' ', $jsLibsData);
//$jsData = preg_replace('/\s+/', ' ', $jsData);
$newJS = $jsLibsData."\n".$jsData;
echo $newJS;
} else {
echo "// Files not avalable or no files specified.";
}
?>
Answer the question
In order to leave comments, you need to log in
Things like this are easier to do without regular expressions. And the regex seems to consume a lot of memory.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question