Get division height in php using simple_html_dom

  <div id="divReportHeader">
     <div class="row-fluid">                                            
        <div class="SpanSimple" style="width: 569px; height: 26.456692913px;
                  margin:0px; border: 2px solid black;">    
            <div style="font-family: 'Times New Roman'; font-size: 26.66px;
             text-align: center; vertical-align: text-top;
                font-style: italic; font-weight: bold; text-decoration: none;"> 
               Country Details
            </div>                                          
       </div>                                       
   </div>
</div>

I have above html inside php variable $headerHtml, I want to get the height of division .SpanSimple, including boarder-width, margin-topand margin-bottom. I tried using the code below, using simple_html_domto get the height, but that doesn't help.

$html = str_get_html($headerHtml); 
$e = $html->find("div", 2);
echo $e->height;

any suggestions or links?

+4
source share
3 answers

PHP is a server-side language, and I doubt that you can use it to get the height of division.

However, you can use javascript to do this:

$(".SpanSimple").height()
+1
source

I tried your code, and in your case, this:

echo $e->style;

And you will get options like:

width: 569px; height: 26.456692913px; margin:0px; border: 2px solid black;

print_r($e) var_dump($e) .

+1

, , style div, simple_html_dom. , height .

$html = str_get_html($headerHtml); 
$e = $html->find("div", 2);
$tempStyleArray = array_map('trim', preg_split( "/[:;]+/", $e->style ));
$tempKey = array_search('height', $tempStyleArray);
$tempHeight = substr($tempStyleArray[$tempKey+1], 0, -2); //removing 'px'
echo $tempHeight;
0
source

Source: https://habr.com/ru/post/1583797/


All Articles