Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4014484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:30:09+00:00 2026-05-20T09:30:09+00:00

How i can get: <p>first<br>p</p> <p>second p</p> from: <p>first p</p> <p>second p</p> using HTMLPurifier?

  • 0

How i can get:

<p>first<br>p</p>
<p>second p</p>

from:

<p>first
p</p>
<p>second p</p>

using HTMLPurifier?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:30:10+00:00Added an answer on May 20, 2026 at 9:30 am

    I’m not sure about the specifics, but since this question has no answers, see if these pointers help you:

    If you’re really set on solving this with HTML Purifier, you might be able to write a textnode transformation that does an nl2br or str_replace by writing a class that extends HTMLPurifier_AttrDef_Text. Pseudocode:

    class HTMLPurifier_AttrDef_Text_Linebreaks extends HTMLPurifier_AttrDef_Text
    {
        public function validate($string, $config, $context) {
            $string = parent::validate($string, $config, $context);
            return str_replace("\n", "<br />", $string);
        }
    }
    

    Then you’d inject your class into HTML Purifier:

    $purifier->set('HTML.DefinitionID', 'aNameForYourDefinition');
    $purifier->set('HTML.DefinitionRev', 1);
    //$purifier->set('Cache.DefinitionImpl', null);
    $htmlDef = $purifier->config->getHTMLDefinition();
    $htmlDef->manager->attrTypes->set(
         'Text',
         new HTMLPurifier_AttrDef_Text_Linebreaks()
    );
    

    Caveats:

    1. The Text AttrDef may be htmlspecialchars()-ed (it’d be sane, really). Then you’re out of luck with that approach. You’d have to find a way to inject a <br /> node, instead.
    2. That might be too late in the process to give you the control you want – that changes the text nodes ‘template’ (so to speak), but the actual HTML definition might already happily be making use of a HTMLPurifier_AttrDef_Text instance.

    See if that helps you at all?

    There’s also a thread on the HTML Purifier forum (did you start it? I wouldn’t be surprised) – nl2br, auto <br /> insertion. If you find a solution, you could post your answer there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get 'second' in the following sample web address. http://www.mywebsite.com/first/sedond/third.html first can
How can I get first and last days of the current week? What I
I can get the the first row in a ListView item in .NET 3.5
First shot at throwing a question on these boards so hopefully I can get
How can I ignore first element and get rest of the elements? <ul> <li><a
I can get easily see what projects and dlls a single project references from
The objective is to get an array of MemberExpressions from two LambdaExpressions. The first
I want to get tag the names from a page using jquery so I
How do I get the values from the Parameters field (second screenshot) in the
I can't work out how to get the contents of the second span 'cantfindme'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.