Am getting a list of HTML tags by the code below:
Code:
<?php
// Heavy testing:
ini_set('memory_limit', '400M');
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents('index.php')); // Don't know how to make it use the loaded document
$xpath = new DOMXpath($doc);
$nodes = $xpath->query('//*');
$names = array();
foreach ($nodes as $node) {
$names[] = $node->nodeName;
}
echo join(PHP_EOL, array_unique($names));
// Source: https://gist.github.com/kwoodfriend/9669711
?>
Output:
html
body
p
title
link
meta
div
article
h1
b
strong
br
hr
h2
ul
li
ol
s
cite
a
h3
But it needs to add a comma(,
) in between tags.
I have the following code:
<?php
$data = file_get_contents("$names"); //read the file
$convert = explode("
", $data); //create array separate by new line
for ($i=0;$i<count($convert);$i++)
{
echo $convert[$i].', '; //write value by index
}
// Source: https://php.net/manual/it/function.file-get-contents.php#102319
?>
That just adds the comma at the end of the line.
The desired result is every tag starting body
and below.(not double of the same tag: p, div, p, etc...)
p, div, article, h1, b, strong, br, hr, h2, ul, li, ol, s, cite, a, h3 {
}
As you can see, i also need to add some CSS
code in between of {
and }
.