Gdn_Format::html PHP Method

html() public static method

Does "magic" formatting of links, mentions, link embeds, emoji, & linebreaks.
public static html ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
return string HTML
    public static function html($Mixed)
    {
        if (!is_string($Mixed)) {
            return self::to($Mixed, 'Html');
        } else {
            if (self::isHtml($Mixed)) {
                // Purify HTML
                $Mixed = Gdn_Format::htmlFilter($Mixed);
                // nl2br
                if (c('Garden.Format.ReplaceNewlines', true)) {
                    $Mixed = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $Mixed);
                    $Mixed = fixNl2Br($Mixed);
                }
                $Result = Gdn_Format::processHTML($Mixed);
            } else {
                // The text does not contain HTML and does not have to be purified.
                // This is an optimization because purifying is very slow and memory intense.
                $Result = htmlspecialchars($Mixed, ENT_NOQUOTES, 'UTF-8');
                if (c('Garden.Format.ReplaceNewlines', true)) {
                    $Result = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $Result);
                    $Result = fixNl2Br($Result);
                }
                $Result = Gdn_Format::processHTML($Result);
            }
            return $Result;
        }
    }

Usage Example

示例#1
0
/**
 *
 *
 * @param $Data
 */
function _checkTable($Data)
{
    echo "<table class='Data' width='100%' style='table-layout: fixed;'>\n";
    echo "<thead><tr><td width='20%'>Field</td><td width='45%'>Current</td><td width='35%'>File</td></tr></thead>";
    $First = true;
    foreach ($Data as $Key => $Value) {
        if (stringBeginsWith($Key, 'File_') || is_array($Value) || $Key == 'Name') {
            continue;
        }
        $Value = Gdn_Format::html($Value);
        $FileValue = Gdn_Format::html(val('File_' . $Key, $Data));
        if ($Key == 'MD5') {
            $Value = substr($Value, 0, 10);
            $FileValue = substr($FileValue, 0, 10);
        }
        if ($Key == 'FileSize') {
            $Value = Gdn_Upload::FormatFileSize($Value);
        }
        echo "<tr><td>{$Key}</td><td>{$Value}</td>";
        if ($Error = val('File_Error', $Data)) {
            if ($First) {
                echo '<td rowspan="4">', htmlspecialchars($Error), '</td>';
            }
        } else {
            echo "<td>{$FileValue}</td></tr>";
        }
        echo "\n";
        $First = false;
    }
    echo '</table>';
}
All Usage Examples Of Gdn_Format::html