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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:51:19+00:00 2026-05-16T18:51:19+00:00

Given a DIV with this general structure (class=post, from an extracted message board post)

  • 0

Given a DIV with this general structure (class=”post”, from an extracted message board post)


<div class="post" id="1575524">
    I'm not sure why these items in the construction updates caught my eye, but they did...<br />
    <br />
    <div style="margin:20px; margin-top:5px; ">
        <div class="smallfont" style="margin-bottom:2px">Quote:</div>
        <table cellpadding="6" cellspacing="0" border="0" width="100%">
        <tr>
            <td class="alt2" style="border:1px inset">

                    Bay Lake Tower – bathroom modifications.

            </td>
        </tr>
        </table>
    </div>They're already having to do stuff to BLT?<br />
    <div style="margin:20px; margin-top:5px; ">
        <div class="smallfont" style="margin-bottom:2px">Quote:</div>
        <table cellpadding="6" cellspacing="0" border="0" width="100%">
        <tr>
            <td class="alt2" style="border:1px inset">

                    Caribbean Beach Resort – refurbish pool rules and spa rules signs at all pools. <br />
    All Star Resorts – refurbish pool rules and spa rules signs. 

            </td>
        </tr>
        </table>
    </div>I bet there are a lot of jurisdictions out there that would love to get building permit fees from this level of work.
</div>

I need to apply CSS styles to the “post” DIV’s plain text, without touching its other child elements (Ps, tables, other DIVs, etc). I cannot change the way the “post” DIV is constructed before I receive it; I can alter it after receiving it and before outputting it as much as necessary. I’m using PHP to output HTML. There’s a linked CSS stylesheet that could take additional styles if needed. There could be any number of blocks of plain text inside the “post” DIV which need to be styled, and any number of child elements which should be left alone.

I have been working with PHP’s string-handling functions (stripos, strripos, substr). The below code does successfully wrap plain plain text before the first child element (“I’m not sure why these items…”) and after the last (“I bet there are a lot of jurisdictions…”) in P tags. The problem is accessing the plain text in between child elements (“They’re already having to…”).


if ( stripos ( $postMessage, '<div' ) !== FALSE ) {
//  wrap text outside divs, if any
//  start of first div
  $divStartPos = stripos ( $postMessage, '<div' );
//  end of last div
  $divEndPos = strripos ( $postMessage, '/div>' ) + 4;
//  all up to start of first div + <p> tags
  if ( $divStartPos > 0 ) { 
    $textBeforeDiv = "<p class=\"postMessage\">". substr ( $postMessage, 0, $divStartPos -1 ) . "</p>\n";
  } // if
//  all between start of first and end of last div
  $div = substr ( $postMessage, $divStartPos, ($divEndPos - $divStartPos) + 1 );
//  all after end of last div + <p> tags
  $textAfterDiv = "<p class=\"postMessage\">". substr ( $postMessage, $divEndPos + 1, $postMessage->length - 1 ) . "</p>\n";
  $postMessage = $textBeforeDiv . $div . $textAfterDiv;
}   // if

I had spent several hours banging my head against PHP’s DOMDocument / DOMElement classes before switching to string-handling, and would happily remain here if possible. Some simple programmatic way of accessing plain text at the top level of a DIV is all I really need. If such a thing exists.

Thanks in advance.

  • 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-16T18:51:20+00:00Added an answer on May 16, 2026 at 6:51 pm

    I would use two addition indexes, startOfValidArea and endOf…
    the area is where is your text, and the indexes are, where you should put your <p...> and </p> tags or whatever tags

    then you are moving these tags like:
    startof.. set to ending of the root <div> and find the first occassion of < after it, this is the first area
    and then while you arent on the end, get the tag after this mentioned < (like substring between < and ' ' or >) and construct temporary ending tag of this (like </xxx>), of course, be aware of multiple identical tags inside (like <table><table></table></table>)
    search for this temp ending tag and it will be the next startOf… index, again search for the next < and this is the second area and so on..
    hope it is clear and understandable..
    P.S. be aware of tags like <br /> and check every start of < for this situation
    its just an algorithm, i dont code in php, but it should be similar

    Edit: the code, but Im not sure if its working, I dont have localserver to test, hope it will be helpfull

    $textStart = stripos($postMessage, '>')+1;            // startig index for the text to highlight
    $textEnd = stripos($postMessage, '<', $textStartPos);     // ending index for the text to highlight
    
    while($textStart != false && $textEnd != false){
        // while there is still any text to highlight
    
        // insert the highlighting code
        $postMessage = substr ($postMessage, 0, $textStart) . '<p class=\"postMessage\">' . substr ($postMessage, $textStart, $textEnd) . '</p>' . substr ($postMessage, $textEnd, strlen($postMessage);
    
        // get the tag
        $endOfTag = (stripos($postMessage, ' ', $textEnd) < stripos($postMessage, '>', $textEnd)) ? stripos($postMessage, ' ', $textEnd) : stripos($postMessage, '>', $textEnd);
        $tag = substr ($postMessage, $textEnd, $endOfTag); // getting the tag here
    
        if($tag == '<br' || $tag == '<img'){
            // do smthing with not-paired tag, like check if the tag is ending with the '/>' string and then ignore it and get the next tag
        }
    
        $closingTag = '</'.substr($tag,1,strlen($tag));           // creating the closing tag like </div or </p    
        $nextSameTag = stripos($postMessage, $tag, $endTag);
        $nextClosingTag = stripos($postMessage, $closingTag, $nextSameTag);
    
        // loop through the same inner tags like <div>text<div>text</div>text</div>
        while($nextSameTag < $nextClosingTag && $textStart != false && $textEnd != false){  
            $nextSameTag = stripos($postMessage, $tag, $nextClosingTag);
            $nextClosingTag = stripos($postMessage, $closingTag, $nextSameTag);
        }
        $textStart = stripos($postMessage, '>', $nextClosingTag)+1;
        $textEnd = stripos($postMessage, '<', $nextClosingTag);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems like a pretty complicated task to me; step 2,… May 16, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer The correct way to do that is: int pages =… May 16, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer You can nest the SQL to avoid duplicating the SUM… May 16, 2026 at 11:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Given: <div class=subHead>Stock Options</div> <table class=settingTable> <tr> <td colspan=2><b>Limited Stock</b></td> </tr> <tr> <td width=50
Given the following HTML: <asp:content id=Content1 contentplaceholderid=mainContent runat=server> <div class=scrollRow> <table width=100%> <tr> <td
I use this css to set a <div> to maximum height Can anyone give
EDIT: I'm not sure that my original question is clear enough. I need an
i have this code <div id=aggregate style=display:inline> <%=Html.RadioButton(a, 1, true, new {id = meRadio})%><label>Me</label>
Given this example, try making your window smaller such that the size of the
Hey, this should be pretty simple, but it's causing me a lot of grief!
This question was inspired a bit by this question , in which the most
So, I was wondering about the following: I have some main content div and
here is my code: $('.round').each ( function ( ) { var content = $(this).html

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.