generate functionTue, 20 Dec 2022

find if post name appears in any keyword from html string

<?php function has_post_name($post_name, $html_string) { $dom = new DOMDocument; $dom->loadHTML($html_string); $xpath = new DOMXpath($dom); $items = $xpath->query("//*[contains(@class,'widget')]//*[contains(@class,'keyword')]"); foreach ($items as $n) { $text = trim($n->nodeValue); if (strcasecmp($text, $post_name) == 0) { return true; } } return false; } ?>

Questions about programming?Chat with your personal AI assistant