-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.php
More file actions
27 lines (20 loc) · 799 Bytes
/
Copy pathtext.php
File metadata and controls
27 lines (20 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use JustHTML\JustHTML;
$html = <<<'HTML'
<p id="lead">
Earth is a <a href="/planet">planet</a>.
</p>
<template id="card"><strong>Template text</strong></template>
HTML;
$doc = new JustHTML($html);
$lead = $doc->queryFirst('#lead');
$template = $doc->queryFirst('#card');
if ($lead === null || $template === null || $template->templateContent === null) {
throw new RuntimeException('Expected example nodes were not parsed');
}
echo 'Normalized: ' . $lead->toText() . PHP_EOL;
echo 'DOM text: ' . json_encode($lead->textContent) . PHP_EOL;
echo 'Template element: ' . json_encode($template->textContent) . PHP_EOL;
echo 'Template content: ' . json_encode($template->templateContent->textContent) . PHP_EOL;