PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php // Example string containing HTML $string = "<h1>Hello, <b>World!</b></h1> <p>This is a <a href='#'>link</a>. <img src='image.jpg' /></p>"; // Define your whitelist of allowed tags $whitelist = ['b', 'a', 'p', 'img']; // Extract all HTML tags using a regular expression preg_match_all('/<([a-zA-Z0-9]+)(\s[^>]*)?>/i', $string, $matches); // $matches[1] will contain all the tag names $allTags = $matches[1]; // Check each tag against the whitelist $validTags = array_filter($allTags, function($tag) use ($whitelist) { return in_array(strtolower($tag), $whitelist); }); // Display results echo "All tags found: "; print_r($allTags); echo "Valid tags (from whitelist): "; print_r($validTags);
Show:  
Copy Clear