nl2br example



/** * Inserts HTML line breaks before all newlines in a string. * * @param string|null $string * * @return string */
function twig_nl2br($string)
{
    return nl2br($string ?? '');
}

/** * Removes whitespaces between HTML tags. * * @param string|null $string * * @return string */
function twig_spaceless($content)
{
    

            );

            return;
        }

        $translationReader = $this->container->get(Shopware_Components_Translation::class);
        $translation = $translationReader->read($customer['languageId'], 'config_mails', $mailModel->getId());
        $mailModel->setTranslation($translation);

        $mailData = [
            'content' => nl2br($mailModel->getContent()) ?: '',
            'fromMail' => $mailModel->getFromMail() ?: '{config name=mail}',
            'fromName' => $mailModel->getFromName() ?: '{config name=shopName}',
            'subject' => $mailModel->getSubject(),
            'toMail' => $customer['email'],
            'userId' => $userId,
            'status' => ($mode === 'allow' ? 'accepted' : 'rejected'),
        ];
        $this->View()->assign(['success' => true, 'data' => $mailData]);
    }

    /** * Sends the mail to the merchant if the inquiry was * successful or was declined. * * @return void */

  protected function getSourceElement(LanguageInterface $source_language$source_config) {
    if ($source_config) {
      $value = '<span lang="' . $source_language->getId() . '">' . nl2br($source_config) . '</span>';
    }
    else {
      $value = $this->t('(Empty)');
    }

    return [
      '#type' => 'item',
      '#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', [
        // Labels originate from configuration schema and are translatable.         '@label' => $this->t($this->definition->getLabel()),
        '@source_language' => $source_language->getName(),
      ]),
if (UrlHelper::isExternal($more_link_path)) {
          $more_link_url = CoreUrl::fromUri($more_link_path$options);
        }
        else {
          $more_link_url = CoreUrl::fromUserInput('/' . $more_link_path$options);
        }
        $more_link = ' ' . $this->linkGenerator()->generate($more_link_text$more_link_url);
      }
    }

    if (!empty($alter['nl2br'])) {
      $value = nl2br($value);
    }

    if ($value_is_safe) {
      $value = ViewsRenderPipelineMarkup::create($value);
    }
    $this->last_render_text = $value;

    if (!empty($alter['make_link']) && (!empty($alter['path']) || !empty($alter['url']))) {
      if (!isset($tokens)) {
        $tokens = $this->getRenderTokens($alter);
      }
      
<?= $this->include('assets/images/chevron-right.svg'); ?></span> <?php } ?> <a href="#trace-box-1"><?= $this->abbrClass($exception->getClass()); ?></a> </h2> <h2 class="exception-http"> HTTP <?= $statusCode; ?> <small><?= $statusText; ?></small> </h2> </div> </div> <div class="exception-message-wrapper"> <div class="container"> <h1 class="break-long-words exception-message<?= mb_strlen($exceptionMessage) > 180 ? ' long' : ''; ?>"><?= $this->formatFileFromText(nl2br($exceptionMessage)); ?></h1> <div class="exception-illustration hidden-xs-down"> <?= $this->include('assets/images/symfony-ghost.svg.php'); ?> </div> </div> </div> </div> <div class="container"> <div class="sf-tabs"> <div class="tab">
<?= file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'debug.js') ?> </script> </head> <body onload="init()"> <!-- Header --> <div class="header"> <div class="container"> <h1><?= esc($title)esc($exception->getCode() ? ' #' . $exception->getCode() : '') ?></h1> <p> <?= nl2br(esc($exception->getMessage())) ?> <a href="https://www.duckduckgo.com/?q=<?= urlencode($title . ' ' . preg_replace('#\'.*\'|".*"#Us', '', $exception->getMessage())) ?>" rel="noreferrer" target="_blank">search &rarr;</a> </p> </div> </div> <!-- Source --> <div class="container"> <p><b><?= esc(clean_path($file)) ?></b> at line <b><?= esc($line) ?></b></p> <?php if (is_file($file)) : ?>
<?php if (ENVIRONMENT !== 'production') : ?> <?= nl2br(esc($message)) ?> <?php else : ?> <?= lang('Errors.sorryCannotFind') ?> <?php endif ?> </p> </div> </body> </html>
public function testStringFormatter() {
    $value = $this->randomString();
    $value .= "\n\n<strong>" . $this->randomString() . '</strong>';
    $value .= "\n\n" . $this->randomString();

    $entity = EntityTestRev::create([]);
    $entity->{$this->fieldName}->value = $value;

    // Verify that all HTML is escaped and newlines are retained.     $this->renderEntityFields($entity$this->display);
    $this->assertNoRaw($value);
    $this->assertRaw(nl2br(Html::escape($value)));

    // Verify the cache tags.     $build = $entity->{$this->fieldName}->view();
    $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');

    $value = $this->randomMachineName();
    $entity->{$this->fieldName}->value = $value;
    $entity->save();

    // Set the formatter to link to the entity.     $this->display->setComponent($this->fieldName, [
      
public function testStringFormatter() {
    $value = $this->randomString();
    $value .= "\n\n<strong>" . $this->randomString() . '</strong>';
    $value .= "\n\n" . $this->randomString();

    $entity = EntityTest::create([]);
    $entity->{$this->fieldName}->value = $value;

    // Verify that all HTML is escaped and newlines are retained.     $this->renderEntityFields($entity$this->display);
    $this->assertNoRaw($value);
    $this->assertRaw(nl2br(Html::escape($value)));

    // Verify the cache tags.     $build = $entity->{$this->fieldName}->view();
    $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
  }

}
<?= $this->include('assets/images/chevron-right.svg'); ?></span> <?php } ?> <a href="#trace-box-1"><?= $this->abbrClass($exception->getClass()); ?></a> </h2> <h2 class="exception-http"> HTTP <?= $statusCode; ?> <small><?= $statusText; ?></small> </h2> </div> </div> <div class="exception-message-wrapper"> <div class="container"> <h1 class="break-long-words exception-message<?= mb_strlen($exceptionMessage) > 180 ? ' long' : ''; ?>"><?= $this->formatFileFromText(nl2br($exceptionMessage)); ?></h1> <div class="exception-illustration hidden-xs-down"> <?= $this->include('assets/images/symfony-ghost.svg.php'); ?> </div> </div> </div> </div> <div class="container"> <div class="sf-tabs"> <div class="tab">
/** * Convert newlines to HTML line breaks except within PRE tags */
    public function nl2brExceptPre(string $str): string
    {
        $newstr   = '';
        $docTypes = new DocTypes();

        for ($ex = explode('pre>', $str)$ct = count($ex)$i = 0; $i < $ct$i++) {
            $xhtml = ! ($docTypes->html5 ?? false);
            $newstr .= (($i % 2) === 0) ? nl2br($ex[$i]$xhtml) : $ex[$i];

            if ($ct - 1 !== $i) {
                $newstr .= 'pre>';
            }
        }

        return $newstr;
    }
}
Home | Imprint | This part of the site doesn't use cookies.