Get Text With PHP Simple HTML DOM Parser
I am using PHP Simple HTML DOM Parser to get text from a webpage. I need to manipulate a page:
<html>
<head>
<title>title</title>
<body>
<div id="content">
<h1>HELLO</h1>
Hello, world!
</div>
</body>
</html>
I need to get an element h1
and text that has no tags. for getting h1
i use this code:
$html = file_get_html("remote_page.html");
foreach($html->find('#content') as $text){
echo "H1: ".$text->find('h1', 0)->plaintext;
}
But a different text? I've also tried this in foreach, but I get the full text:
$text->plaintext;
but it also returned a tag h1
...
source to share
Use stripe tags as @Peachy pointed out. However, passing the second argument to <br>
it means that the string will ignore tags <br>
, which is optional. In your case
<?php
strip_tags($text);
?>
will work the way you would like, given that you are only selecting content in content
id.
source to share