Converti une chaine encodée en base64 en fichier
@param string $content
978646
public function writeBase64 ($content)
    {
        $parts = explode(',', $content);
        if(count($parts) > 1) {
            $base64_encoded = $parts[1];
            $this->writeOver(base64_decode($base64_encoded));
            return self::FILE_CREATE_SUCCESS;
        } else {
            return self::FILE_CREATE_ERROR;
        }

    }
146234
public static function encode_content_links($content) {
        global $CFG;

        $base = preg_quote($CFG->wwwroot, '/');

        // Link to the list of quizzes.
        $search="/(".$base."\/mod\/quiz\/index.php\?id\=)([0-9]+)/";
        $content= preg_replace($search, '$@QUIZINDEX*$2@$', $content);

        // Link to quiz view by moduleid.
        $search="/(".$base."\/mod\/quiz\/view.php\?id\=)([0-9]+)/";
        $content= preg_replace($search, '$@QUIZVIEWBYID*$2@$', $content);

        // Link to quiz view by quizid.
        $search="/(".$base."\/mod\/quiz\/view.php\?q\=)([0-9]+)/";
        $content= preg_replace($search, '$@QUIZVIEWBYQ*$2@$', $content);

        return $content;
    }
1115387
public function filter($value)
    {
        // TODO : Traiter UTF8 et le remplissage depuis un autre champ si vide
        $value = strtolower($value);
        $value = str_replace("'", '', $value);
        $value = preg_replace('([^a-zA-Z0-9_-]+)', '-', $value);
        $value = preg_replace('(-{2,})', '-', $value);
        $value = trim($value, '-');

        /*if ($this->options['encoding'] !== null) {
            return mb_strtolower((string) $value,  $this->options['encoding']);
        }*/

        return $value;
    }
1051660
private function utf8ToCharset($content, $encoding = null)
    {
        if ('UTF-8' !== $encoding && !empty($encoding)) {
            if (function_exists('mb_convert_encoding')) {
                return mb_convert_encoding($content, $encoding, 'UTF-8');
            }

            if (function_exists('iconv')) {
                return iconv('UTF-8', $encoding, $content);
            }

            throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
        }

        return $content;
    }
789775
public function setContent($content)
	{
		$this->original = $content;

		$status = $this->getStatusCode();
		$reason = '';
		$output = '';

		switch ($this->headers->get('content-type'))
		{
			case 'text/plain':
				/*if ($suppress_response_codes)
				{
					$output .= "Status: $status\n";
					$output .= "Reason: $reason\n";
					$output .= "\n";
				}*/

				if (!is_object($content) && !is_array($content))
				{
					$output .= $content;
				}
				else
				{
					$output .= json_encode($content);
				}
			break;

			case 'text/html':
				$reason  = htmlspecialchars($reason);
				$content = htmlspecialchars($content);

				$output .= "<!DOCTYPE html>\n";
				$output .= "<html lang='en'>\n";
				$output .= "<head>\n";
				$output .= "<meta charset='utf-8'>\n";
				$output .= "<title>$status $reason</title>\n";
				$output .= "</head>\n";
				$output .= "<body>\n";
				$output .= '<div class="error">' . "\n";

				$output .= '<h1 id="reason">' . $reason . "</h1>\n";

				if ($suppress_response_codes)
				{
					$output .= '<p id="status">' . htmlspecialchars($status) . "</p>\n";
				}

				if (!is_object($content) && !is_array($content))
				{
					$output .= '<p id ="message">' . $content . "</p>\n";
				}
				else
				{
					$output .= '<p id ="message">' . json_encode($content) . "</p>\n";
				}

				$output .= "</div>\n";
				$output .= "</body>\n";
				$output .= "</html>";
			break;
			case 'application/xhtml+xml':
				$reason  = htmlspecialchars($reason);
				$content = htmlspecialchars($content);

				$output .= '<?xml version="1.0" ?>' . "\n";
				$output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
				$output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n";
				$output .= "<head>\n";
				$output .= "<title>$status $reason</title>\n";
				$output .= "</head>\n";
				$output .= "<body>\n";
				$output .= '<div class="error">' . "\n";

				$output .= '<h1 id="reason">' . $reason . "</h1>\n";

				if ($suppress_response_codes)
				{
					$output .= '<p id="status">' . htmlspecialchars($status) . "</p>\n";
				}
				if (!is_object($content) && !is_array($content))
				{
					$output .= '<p id ="message">' . $content . "</p>\n";
				}
				else
				{
					$output .= '<p id ="message">' . json_encode($content) . "</p>\n";
				}

				$output .= "</div>\n";
				$output .= "</body>\n";
				$output .= "</html>";
			break;
			case "application/xml":
				$output .= Xml::encode($content);
			break;
			case 'application/json':
				$output .= json_encode($content);
			break;
			case 'application/javascript':
				$output .= $content;
			break;
			case 'application/vnd.php.serialized':
				$output .= serialize($content);
			break;
			case 'application/php':
				$output .= var_export($content, true);
			break;
			case 'application/x-www-form-urlencoded':
				if (!is_object($content))
				{
					$output .= $content;
				}
				else
				{
					$output .= json_encode($content);
				}
			break;
		}

		return parent::setContent($output);
	}
945285
protected static function compressFiles($content)
    {
        $var = ["\r\n", "\r", "\n", "\t", '  ', '    ', '    '];

        $content = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $content);

        $content = str_replace($var, '', $content);
        $content = str_replace('{ ', '{', $content);
        $content = str_replace(' }', '}', $content);
        $content = str_replace('; ', ';', $content);

        return $content;
    }
1190024
private function fixContentEncoding($content)
    {
        if (!empty($content)) {
            // Little hack to force UTF-8
            if (false === strpos($content, '<?xml encoding')) {
                $hack = false === strpos(
                    $content,
                    '<body'
                ) ? '<?xml encoding="UTF-8"><body>' : '<?xml encoding="UTF-8">';
                $content = $hack.$content;
            }

            $encoding = mb_detect_encoding($content);
            $headPos = mb_strpos($content, '<head>');

            // Add a meta to the <head> section
            if (false !== $headPos) {
                $headPos += 6;
                $content = mb_substr($content, 0, $headPos).
                    '<meta http-equiv="Content-Type" content="text/html; charset='.$encoding.'">'.
                    mb_substr($content, $headPos);
            }

            $content = mb_convert_encoding($content, 'HTML-ENTITIES', $encoding);
        }

        return $content;
    }
312853
public function encode(Content $content): string
    {
        $results     = [];
        $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
        foreach ($content->getFields() as $field) {
            $identifier      = $field->fieldDefIdentifier;
            $fieldDefinition = $contentType->getFieldDefinition($identifier);
            if (!$fieldDefinition->isTranslatable) {
                continue;
            }
            $type = \get_class($field->value);
            // Note that TextBlock is a TextLine
            if ($field->value instanceof TextLineValue) {
                $value                = (string) $field->value;
                $results[$identifier] = ['#' => $value, '@type' => $type];
                continue;
            }
            if ($field->value instanceof RichTextValue
                || $field->value instanceof EzPlatformRichTextValue
            ) {
                // we need to remove that to make it a good XML
                $value                = $this->richTextEncode($field->value);
                $results[$identifier] = ['#' => $value, '@type' => $type];
            }
        }

        $encoder = new XmlEncoder();
        $payload = $encoder->encode($results, XmlEncoder::FORMAT);
        // here Encoder has  decorated with CDATA, we don't want the CDATA
        $payload = str_replace(
            ['<![CDATA[', ']]>'],
            ['<' . self::CDATA_FAKER_TAG . '>', '</' . self::CDATA_FAKER_TAG . '>'],
            $payload
        );

        return $payload;
    }
1229507
private function convertBase64ToDec($value)
    {
        $value = unpack('H*', Base64Url::decode($value));

        return $this->convertHexToDec($value[1]);
    }
79386
protected function processNoConvert(string &$content): void
    {
        $pattern = '/{!}(' . preg_quote($this->startTag) . '.+?' . preg_quote($this->endTag) . ')/s';
        $content = preg_replace($pattern, '\1', $content);
    }
746041
public static String encode(String content) {
		if (content == null || content.length() == 0) {
			return content;
		}
		return org.apache.commons.codec.binary.Base64.encodeBase64String(content.getBytes()).trim();

	}
1205005
protected function _replaceCdata($content) {
		foreach ($this->_cdata as $n => $data) {
			$data = '<![CDATA[' . $data . ']]>';
			$content = str_replace('###CDATA-' . $n . '###', $data, $content);
		}
		return $content;
	}
587404
public static function convert($content, $mode = ParserAbstract::MODE_STRICT)
    {
        $parser = new self($mode);

        return $parser->parse($content);
    }
18450
@JsonIgnore
    public void encodeAndSetContent(String content) {
        encodeAndSetContent(content != null ? content.getBytes() : null);
    }
1189482
public static String encodeBase64(String content, TestContext context) {
        return new EncodeBase64Function().execute(Collections.singletonList(content), context);
    }
454502
public function write($content)
    {
        if (!$this->isOpen()) {
            $this->open();
        }

        return fwrite($this->stream, $content);
    }
2792
protected function putContentToTmpFile($content)
    {
        $path = $this->createTempFilePath(self::HTML_EXTENSION);

        $this->createFile($path, $content);

        return $path;
    }