Parse response with PHP's HTML Tidy extension

@param  string
@return string
187550
public function parse($input)
	{
		// Parse input
		$tidy = new PhpTidy;
		$tidy->parseString($input, $this->tidy_options, $this->encoding);
		$tidy->cleanRepair();

		// Set doctype
		$output = $this->doctype . "\n" . preg_replace('_ xmlns="http://www.w3.org/1999/xhtml"_', null, $tidy, 1);

		// Append errors
		if ($this->display_errors and $tidy->getStatus())
		{
			// Omit ignored errors
			$errors = $tidy->errorBuffer;
			foreach($this->ignored_errors as $regex)
				$errors = preg_replace($regex, null, $errors);

			// Wrap errors in a container
			if (strlen($errors))
				$errors = $this->container_open_tag . nl2br(htmlentities($errors)) . $this->container_close_tag;

			// Append errors at the end of the document
			$output = str_replace('</body>', $errors . '</body>', $output);
		}

		return $output;
	}
93737
public function parseHeader()
    {
        //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n"));
        
        $rawHeaders = rtrim($this->response['headerRaw'], "\r\n");
        # Handle multiple responses e.g. with redirections (proxies too)
        $headerGroups = explode("\r\n\r\n", $rawHeaders);
        # We're only interested in the last one
        $header = explode("\r\n", end($headerGroups));

        $output = array();

        if ('HTTP' === substr($header[0], 0, 4)) {
            list($output['version'], $output['status']) = explode(' ', $header[0]);
            unset($header[0]);
        }

        foreach ($header as $entry) {
            $pos = strpos($entry, ':');
            $output[trim(substr($entry, 0, $pos))] = trim(substr($entry, $pos + 1));
        }

        $this->response['header'] = $output;
        return $this;
    }
1207718
protected function sanitizeString($string)
    {
        // clean content
        $string = HtmlContentExtractor::cleanContent($string);
        $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
        $string = filter_var(strip_tags($string), FILTER_SANITIZE_STRING); // after entity decoding we might have tags again
        $string = trim($string);

        return $string;
    }
274105
private function parseResponse($res) {
    $contents = explode("\n", $res);

    // Response comes back as HTTP/1.1 200 OK
    // Final line contains HTTP response.
    $status = explode(" ", $contents[0], 3);
    $result = $contents[count($contents) - 1];

    return array(
      "status"  => isset($status[1]) ? $status[1] : null,
      "message" => $result
    );
  }
563262
public function parse_tag_response( $response ) {
		if ( $this->validate_response( $response ) ) {
			return $response;
		}

		$arr = [];
		array_map(
			function ( $e ) use ( &$arr ) {
				$arr[] = $e->name;

				return $arr;
			},
			(array) $response
		);

		return $arr;
	}
273405
function parse() {
        $name_without_parens = preg_replace('/[{}]/', '', $this->full_name);

        $parts = explode('::', $name_without_parens);
        $name_without_case_keys = trim($parts[0]);
        array_shift($parts);
        $this->case_keys = array_map('trim', $parts);

        $parts = explode(':', $name_without_case_keys);
        $this->short_name = trim($parts[0]);
        array_shift($parts);
        $this->context_keys = array_map('trim', $parts);
    }
932517
public function tidy() {
        $stringy = self::create($this->str, $this->encoding);

        $stringy->str = preg_replace('/\x{2026}/u', '...', $stringy->str);
        $stringy->str = preg_replace('/[\x{201C}\x{201D}]/u', '"', $stringy->str);
        $stringy->str = preg_replace('/[\x{2018}\x{2019}]/u', "'", $stringy->str);
        $stringy->str = preg_replace('/[\x{2013}\x{2014}]/u', '-', $stringy->str);

        return $stringy;
    }
112285
public function process($string)
    {
        preg_match_all($this->tagFilter, $string, $matches);

        if (!$matches) {
            return $string;
        }

        foreach ($matches[0] as $i => $m) {
            if (array_key_exists($matches[1][$i], $this->styles)) {
                $string = $this->replaceColors(
                    $string,
                    $matches[1][$i],
                    $matches[2][$i],
                    $this->styles[$matches[1][$i]]
                );
            } elseif (strpos($matches[1][$i], '=')) {
                // Custom format
                $string = $this->replaceColors(
                    $string,
                    $matches[1][$i],
                    $matches[2][$i],
                    ColorStyle::fromString($matches[1][$i])
                );
            }
        }

        return $string;
    }
1255
private function vulgarize($string)
    {
        return trim(
            preg_replace(
                '/(-+)/',
                '-',
                preg_replace(
                    '/([^a-z0-9-]*)/',
                    '',
                    preg_replace(
                        '/((\s|\.|\'|\/)+)/',
                        '-',
                        html_entity_decode(
                            preg_replace(
                                '/&(a|o)elig;/',
                                '$1e',
                                preg_replace(
                                    '/&([a-z])(uml|acute|grave|circ|tilde|ring|cedil|slash);/',
                                    '$1',
                                    strtolower(
                                        htmlentities(
                                            $string,
                                            ENT_COMPAT,
                                            'utf-8'
                                        )
                                    )
                                )
                            ),
                            ENT_COMPAT,
                            'utf-8'
                        )
                    )
                )
            ),
            '-'
        );
    }
709765
public function parse($string, array $whitelist = array(), $wrap = true) {
        $parsed = $this->getDecoda()->reset($string)->whitelist($whitelist)->parse();

        if ($wrap) {
            return $this->Html->div('decoda', $parsed);
        }

        return $parsed;
    }
1299097
function stripHTTPHeader( $data )
    {
        $missingxml = false;
        $start = strpos( $data, "<?xml" );
        if ( $start === false )
        {
            eZDebug::writeWarning( "missing <?xml ...> in HTTP response, attempting workaround", __METHOD__ );
            $start = strpos( $data, "<E:Envelope" );
            $missingxml = true;
        }
        $data = substr( $data, $start, strlen( $data ) - $start );

        if ( $missingxml == true )
        {
            $data = '<?xml version="1.0"?>' . $data;
        }

        return $data;
    }
579087
public function digest($string)
    {
        // protect against missing data
        $needed = array(
            'nonce' => 1,
            'nc' => 1,
            'cnonce' => 1,
            'qop' => 1,
            'username' => 1,
            'uri' => 1,
            'response' => 1);
        
        $data = array();
        $keys = implode('|', array_keys($needed));
    
        preg_match_all(
            '@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@',
            $string,
            $matches,
            PREG_SET_ORDER
        );
    
        foreach ($matches as $match) {
            $data[$match[1]] = $match[3] ? $match[3] : $match[4];
            unset($needed[$match[1]]);
        }
    
        return $needed ? false : $data;
    }
310105
public function clean($string)
    {
        $reg = '#'.preg_quote($this->browser->getHost()).'/ch\d+ \[([^\]]+)\]#';
        $string = preg_replace($reg, '$1', $string);
        $string = preg_replace('/\[[^\[\]]+\]/', '', $string); // remove BB tags

        return $string;
    }
416254
protected function doParse($string)
    {
        $userAgent = array(
            'string' => $this->cleanString($string),
            'browser_name' => null,
            'browser_version' => null,
            'browser_engine' => null,
            'operating_system' => null,
            'device' => 'Other'
        );

        if (empty($userAgent['string'])) {
            return $userAgent;
        }

        $browsers = $this->definition->getKnownBrowsers();
        $bots = $this->definition->getKnownBots();
        $userAgents = $browsers + $bots;

        // Find the right name/version phrase (or return empty array if none found)
        foreach ($userAgents as $name => $regexes) {
            if ($matches = $this->matchBrowser($regexes, $userAgent['string'])) {
                if (isset($matches[3])) {
                    $name = str_replace('*', strtolower($matches[2]), $name);
                }

                $userAgent['browser_name'] = $name;
                $userAgent['browser_version'] = end($matches);

                break;
            }
        }

        // Find browser engine
        $engines = $this->definition->getKnownEngines();
        if ($result = $this->find($engines, $userAgent['string'])) {
            $userAgent['browser_engine'] = $result;
        }

        // Find operating system
        $operatingSystems = $this->definition->getKnownOperatingSystems();
        if ($result = $this->find($operatingSystems, $userAgent['string'])) {
            $userAgent['operating_system'] = $result;
        }

        // Find device name
        $devices = $this->definition->getKnownDevices();
        if ($result = $this->find($devices, $userAgent['string'], true)) {
            $userAgent['device'] = $result;
        }

        return $userAgent;
    }
1076115
public function parseString($string)
    {

        $stringHelper = $this->container->get('opifer.content.string_helper');

        $string = $stringHelper->replaceLinks($string);

        return $string;
    }
1210815
public function extractResponseHeadersAndBody()
    {
        $parts = explode("\r\n\r\n", $this->rawResponse);
        $rawBody = array_pop($parts);
        $rawHeaders = implode("\r\n\r\n", $parts);

        return [trim($rawHeaders), trim($rawBody)];
    }
1222121
protected function parseCurlResponse($response)
    {
        $pattern = '|HTTP/\d\.\d.*?$.*?\r\n\r\n|ims';
        preg_match_all($pattern, $response, $matches);
        $header = array_pop($matches[0]);
        # Remove headers from the response body
        $body = str_replace($header, '', $response);

        return array(
            'header' => $header,
            'body' => $body,
        );
    }