N
N
NO2014-07-24 17:07:35
PHP
NO, 2014-07-24 17:07:35

"Simple HTML DOM Parser" how to remove tags?

There is an HTML code:

<html>
<head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">
<style type="text/css">
<!--
span.cls_004{font-family:Arial,serif;font-size:18.1px;color:rgb(255,255,255);font-weight:bold;font-style:normal;text-decoration: none}
-->
</style>
<script type="text/javascript" src="Utah motorcycleFactSheet2012_files/wz_jsgraphics.js"></script>
</head>
<body>
<div style="position:absolute;left:50%;margin-left:-306px;top:0px;width:612px;height:792px;border-style:outset;overflow:hidden">
<div style="position:absolute;left:0px;top:0px">
<img src="Utah motorcycleFactSheet2012_files/background1.jpg" width=612 height=792></div>
<div style="position:absolute;left:29.88px;top:32.86px" class="cls_004"><span class="cls_004">2012 Utah Crash Facts</span></div>
</div>
</body>
</html>

From which you need to remove the following HTML tags:
<html>
<head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">
<script type="text/javascript" src="Utah motorcycleFactSheet2012_files/wz_jsgraphics.js"></script>
</head>
<body>
</body>
</html>

So I started, but I don't know what to do next:
//if(isset($_POST['k1'])){}
  //$k1 = $_POST['k1'];
  include('simple_html_dom.php');
  $html = new simple_html_dom();
  $html->load('<html>
<head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">
<script type="text/javascript" src="Utah motorcycleFactSheet2012_files/wz_jsgraphics.js"></script>
</head>
<body>
</body>
</html>');
  $element = $html->find("html");
  $element = null;
  echo $html->save();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NO, 2014-07-25
@Mihail9575

I just extracted "style" (Reads the entire HTML of the element, including itself) and "body" (Reads the inner HTML of the element) from the HTML code.

include('simple_html_dom.php');
$html = new simple_html_dom();
$html = str_get_html($k1);

$style = $html->find('style',0);
echo $style->outertext;

$body = $html->find('body',0);
echo $body->innertext;

S
Sergey Nikolaevich, 2014-07-24
@Playmore

Isn't it easier to just select body and take the insides?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question