Skip to content

Instantly share code, notes, and snippets.

View Tim-Otte's full-sized avatar
💻
Coding

Tim Otte Tim-Otte

💻
Coding
View GitHub Profile
@Tim-Otte
Tim-Otte / htmlTagConverter.php
Last active January 9, 2024 21:20
With this script you can convert a string with html tags into an array of html tags with tag name, attributes, inner text and child tags
<?php
define('HTML_REGEX_PATTERN', '/<([a-zA-Z]+)(?:\s([a-zA-Z]+(?:=(?:".+")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(.*)<\/\1>))/');
function isHtmlTag($text) {
return preg_match(HTML_REGEX_PATTERN, $text);
}
function hasHtmlTag($text) {
return preg_match_all(HTML_REGEX_PATTERN, $text);