4

I'm using Php Html Dom Parser to get the elements. But it's not getting and element with inner text. See the code below;

$html = file_get_html($currentFile);
foreach($html->find('style') as $e){
  echo $e->plaintext;
}

I have this type of on page CSS code

<style type="text/css">
ul.gallery li.none { display:none;}
ul.gallery { margin:35px 24px 0 19px;}
</style>
<!--<![endif]-->
<style type="text/css">
body { background:#FFF url(images/bg.gif) repeat-x;}
</style>

and I want to get each and element with inner text.

Thanks

1 Answer 1

5

You're already correct in targeting the style tag. But you need to use the ->innertext magic attribute to get the values. Consider this example:

include 'simple_html_dom.php';
$html_string = '<style type="text/css">ul.gallery li.none { display:none;}ul.gallery { margin:35px 24px 0 19px;}</style><!--<![endif]--><style type="text/css">body { background:#FFF url(images/bg.gif) repeat-x;}</style>';
$html = str_get_html($html_string); // or file_get_html in your case
$styles = array();
foreach($html->find('style') as $style) {
    $styles[] = $style->innertext;
}

echo '<pre>';
print_r($styles);

$styles should output:

Array
(
    [0] => ul.gallery li.none { display:none;}ul.gallery { margin:35px 24px 0 19px;}
    [1] => body { background:#FFF url(images/bg.gif) repeat-x;}
)
Sign up to request clarification or add additional context in comments.

1 Comment

@SmacAfzal no prob bro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.