Exemple #1
0
/**
 * @used-by df_exception_to_session()
 * @param string[] ...$args
 * @return string|string[]
 */
function df_xml_output_html(...$args)
{
    return df_call_a(function ($text) {
        return !df_contains($text, DF_XML_BEGIN) ? $text : preg_replace_callback(sprintf('#%s([\\s\\S]*)%s#mui', DF_XML_BEGIN, DF_XML_END), function (array $matches) {
            return strtr('<pre class="df-xml">{contents}</div>', ['{contents}' => df_e(df_normalize(dfa($matches, 1, '')))]);
        }, $text);
    }, $args);
}
Exemple #2
0
 /**
  * @param string[] ...$args
  * @return string|string[]|array(string => string)
  */
 public function nl2br(...$args)
 {
     return df_call_a(function ($text) {
         /** @var string $result */
         $text = df_normalize($text);
         /** обрабатываем тег <pre>, который добавляется функцией @see df_xml_output_html() */
         if (!df_contains($text, '<pre class=') && !df_contains($text, '<pre>')) {
             $result = nl2br($text);
         } else {
             $text = str_replace("\n", '{rm-newline}', $text);
             $text = preg_replace_callback('#\\<pre(?:\\sclass="[^"]*")?\\>([\\s\\S]*)\\<\\/pre\\>#mui', [__CLASS__, 'nl2brCallback'], $text);
             $result = strtr($text, ['{rm-newline}' => '<br/>', '{rm-newline-preserve}' => "\n"]);
         }
         return $result;
     }, $args);
 }
Exemple #3
0
/**
 * @param string $s
 * @return string[]
 */
function df_explode_n($s)
{
    return explode("\n", df_normalize($s));
}