Return pretty-print view of a literal
This method is mainly intended for internal use and is used by EasyRdf_Graph and EasyRdf_Sparql_Result to format a literal for display.
mixed $literal An EasyRdf_Literal object or an associative array:
bool $html Set to true to format the dump using HTML:
string $color The colour of the text:
string
public static function dumpLiteralValue($literal, $html = true, $color = 'black') {
if (is_object($literal)) {
$literal = $literal
->toArray();
}
elseif (!is_array($literal)) {
$literal = array(
'value' => $literal,
);
}
$text = '"' . $literal['value'] . '"';
if (isset($literal['lang'])) {
$text .= '@' . $literal['lang'];
}
if (isset($literal['datatype'])) {
$datatype = EasyRdf_Namespace::shorten($literal['datatype']);
$text .= "^^{$datatype}";
}
if ($html) {
return "<span style='color:{$color}'>" . htmlentities($text, ENT_COMPAT, "UTF-8") . "</span>";
}
else {
return $text;
}
}