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 3420706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:02:23+00:00 2026-05-18T06:02:23+00:00

considering the following : (mixture of <br> and <br/> ) text1 <br> text2 <br/>

  • 0

considering the following : (mixture of <br> and <br/>)

text1
<br>
text2
<br/>
text3
<br/>
text4
<br>
text5

How can I locate each text nodes ?

I am thinking something that fits the condition of preceding OR following a br tag….but unsure if <br> and <br/> are treated differently in xpath.

  • 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-18T06:02:24+00:00Added an answer on May 18, 2026 at 6:02 am

    DOMDocument‘s loadHtml() method works well with invalid HTML fragments, so you can use DOMXPath this way:

    <?php
    
    $html = 'text1
    <br>
    text2
    <br/>
    text3
    <br/>
    text4
    <br>
    text5';
    
    echo "<pre>" . htmlentities($html) . "</pre><br>\n";
    
    $dom = new DOMDocument();
    // loadHtml() needs mb_convert_encoding() to work well with UTF-8 encoding
    $dom->loadHtml(mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"));
    
    $xpath = new DOMXPath($dom);
    
    echo "Text nodes preceding br:";
    foreach($xpath->query('//text()[(following::br)]') as $node)
    {
        var_dump($node->wholeText);
    }
    
    echo "Text nodes following br:";
    foreach($xpath->query('//text()[(preceding::br)]') as $node)
    {
        var_dump($node->wholeText);
    }
    
    echo "Text nodes following OR preceding br:";
    foreach($xpath->query('//text()[(following::br) or (preceding::br)]') as $node)
    {
        var_dump($node->wholeText);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Considering the following view excerpt : <%= Html.TextBox(Something, Model.Property.SubProperty.Value) %> I can handle the
Considering the following string: String s = /static/201105-3805-somerandom/images/optional-folder/filename.gif; How can I remove the static/201105-3805-somerandom/
Considering following struct and template function, does each use of the function with a
Considering the following table: rowid | text | group 1 | a | 1
Considering the following text pattern, #goals: the process report timestamp, eg. 2011-09-21 15:45:00 and
Say I have a text file of 1 MB. Considering the following the example:
Considering the following setup, how can I restrain IConnection to only contain IPort of
Considering following code public class A { public static void main(String[] args) { new
Considering the following TSQL: INSERT INTO Address(Street1, City, State, ZipCode) SELECT Street1, City, StateCode,
Considering the following table: someId INTEGER #PK ageStart TINYINT(3) ageEnd TINYINT(3) dateBegin INTEGER dateEnd

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.