Remove comments from string

@param string $output

@return string
331523
public static function removeComments($output)
    {
        $lines  = explode("\n", $output);
        $output = "";
        // try to keep mem. use down
        $linecount  = count($lines);
        $in_comment = false;
        for ($i=0; $i<$linecount; $i++) {
            if (preg_match("/^\/\*/", $lines[$i])) {
                $in_comment = true;
            }
            if (!$in_comment) {
                $output .= $lines[$i] . "\n";
            }
            if (preg_match("/\*\/$/", $lines[$i])) {
                $in_comment = false;
            }
        }
        unset($lines);
        return $output;
    }
324893
public static function strip_comments($data)
	{
		$output = '';
		while (($start = strpos($data, '<!--')) !== false)
		{
			$output .= substr($data, 0, $start);
			if (($end = strpos($data, '-->', $start)) !== false)
			{
				$data = substr_replace($data, '', 0, $end + 3);
			}
			else
			{
				$data = '';
			}
		}
		return $output . $data;
	}
67482
private function cleanAnnotations($comment)
    {
        $comment = trim(
            preg_replace(
                '#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u',
                '$1',
                $comment
            )
        );

        // reg ex above is not able to remove */ from a single line docblock
        if (substr($comment, -2) == '*/') {
            $comment = trim(substr($comment, 0, -2));
        }

        // normalize strings
        $comment = str_replace(["\r\n", "\r"], "\n", $comment);

        return $comment;
    }
87164
private function writeToOutputNow($output)
    {
        if ($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) {
            $this->system->setHttpResponseCode(
                $this->sendHttpCode()
            );
        }

        echo $output;

        return $this;
    }
697297
public static function clean($string)
	{
		if (empty($string))
		{
			return $string;
		}

		if (get_magic_quotes_gpc())
		{
			$string = stripslashes($string);
		}

		// strip out any KL_PHP, script, style, HTML comments
		$string = preg_replace('/{kl_php}(.*?){\/kl_php}/is', '', $string);
		$regex =
			'/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|' .
			'<script[^>]*>.*?<\/script>|' .
			'<style[^>]*>.*?<\/style>|' .
			'<\?php.*?\?>|' .
			'<!--.*?-->)/is';
		$string = preg_replace($regex, '', $string);

		$string = str_replace(
			array('&amp;',     '&lt;',     '&gt;'),
			array('&amp;amp;', '&amp;lt;', '&amp;gt;'),
			$string
		);
		// Fix &entitiy\n;

		$string = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u', "$1;", $string);
		$string = preg_replace('#(&\#x*)([0-9A-F]+);*#iu', "$1$2;", $string);
		//$string = html_entity_decode($string, ENT_COMPAT, "UTF-8");

		// Remove any attribute starting with "on" or xmlns
		$string = preg_replace('#(<[^>]+[\x00-\x20\"\'])(on|xmlns)[^>]*>#iUu', "$1>", $string);

		// Remove javascript: and vbscript: protocol
		$string = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*)[\\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2nojavascript...', $string);
		$string = preg_replace('#([a-z]*)[\x00-\x20]*=([\'\"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2novbscript...', $string);

		// <span style="width: expression(alert('Ping!'));"></span>
		// only works in ie...
		$string = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*expression[\x00-\x20]*\([^>]*>#iU', "$1>", $string);
		$string = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*behaviour[\x00-\x20]*\([^>]*>#iU', "$1>", $string);
		$string = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*>#iUu', "$1>", $string);

		// Remove namespaced elements (we do not need them...)
		$string = preg_replace('#</*\w+:\w[^>]*>#i', '', $string);

		// Remove really unwanted tags
		$string = self::stripTags($string,
			'applet', 'meta', 'xml', 'blink', 'link', 'style',
			'script', 'embed', 'object', 'iframe', 'frame', 'frameset',
			'ilayer', 'layer', 'bgsound', 'title', 'base'
		);

		return $string;
	}
1255204
public function removeComment(Comment $comment)
    {
        if ($this->comments->contains($comment)) {
            $this->comments->removeElement($comment);
            $comment->setTask(null);
        }

        return $this;
    }
1209331
protected function cleanOutput($output)
    {
        $output = str_replace($this->extraOutput, null, $output);

        return strtr($output, [
            'stdin: is not a tty' => null,
        ]);
    }
530868
public static function outputStyles($output = '')
    {
        self::lookIfProcessFiles('style', 'header');

        $template = self::$templates['style'];
        $styles = self::$data['style']['header'];

        foreach ($styles as $value) {
            $output .= sprintf(
                $template,
                $value['url']
            );
        }

        self::$data['style']['header'] = [];

        return ! empty($output) ? $output : false;
    }
788702
public static String removeComments(String s) {
        int pos = s.indexOf("#");
        if (pos == -1) {
            return s;
        }
        return s.substring(0,pos).trim();
    }
84646
protected function stripComments()
    {
        // PHP only supports $this inside anonymous functions since 5.4
        $minifier = $this;
        $callback = function ($match) use ($minifier) {
            $count = count($minifier->extracted);
            $placeholder = '/*'.$count.'*/';
            $minifier->extracted[$placeholder] = $match[0];

            return $placeholder;
        };
        // multi-line comments
        $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
        $this->registerPattern('/\/\*.*?\*\//s', '');

        // single-line comments
        $this->registerPattern('/\/\/.*$/m', '');
    }
690430
protected function parse($output)
    {
        $lines = explode(PHP_EOL, $output);
        $stats = array();
        foreach ($lines as $line) {
            $data = explode(' ', $line);
            array_walk($data, 'trim');
            $stats[] = array_values(array_filter($data, function ($value) {
                return strlen($value) > 0;
            }));
        }

        return $stats;
    }
1242370
protected function processOutput(array $output = [])
    {
        $data = null;
        if (is_array($output)) {
            foreach ($output as $item) {
                if (is_string($item)) {
                    if ($this->checkOutputStringForData($item)) {
                        $data = $this->transformOutputStringToData($item);
                    } else {
                        echo $item . PHP_EOL;
                    }
                }
            }
        } elseif (is_string($output)) {
            if ($this->checkOutputStringForData($output)) {
                $data = $this->transformOutputStringToData($output);
            } else {
                echo $output . PHP_EOL;
            }
        }

        return $data;
    }
526617
public static function removeComments($s)
    {
        $pos = strpos($s, '#');

        return false === $pos ? $s : trim(substr($s, 0, $pos));
    }
711514
protected function processOutput($output, $array = false, $trim = true)
    {
        // Remove polluting strings
        $output = $this->cleanOutput($output);

        // Explode output if necessary
        if ($array) {
            $delimiter = $this->environment->getLineEndings() ?: PHP_EOL;
            $output = explode($delimiter, $output);
        }

        // Trim output
        if ($trim) {
            $output = is_array($output)
                ? array_filter($output)
                : trim($output);
        }

        return $output;
    }
928087
function removeComments(obj) {
    const keys = Object.keys(obj);
    const newObj = {};

    for (let i = 0, len = keys.length; i < len; i++) {
      if (!COMMENT_KEY.test(keys[i])) {
        newObj[keys[i]] = obj[keys[i]];
      }
    }

    return newObj;
  }
491660
protected function postrender($output)
    {
        // insert objects' contents
        foreach ($this->objects as $key => $val) {
            $output = str_replace($key, $val, $output, $count);
            if ($count) {
                $this->objects[$key] = null;
            }
        }

        // make sure all <form> tags have a valid request token
        $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output);

        return $output;
    }
838952
protected function outputToCollection(string $output)
    {
        if ($this->target->resource->jsonResult) {
            return collect(json_decode($output, true) ?? collect([]));
        }

        return $output;
    }