Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. $el = 'li'; // Ex
  2. $match = []; // Reserving for results
  3.  
  4. /**
  5. * Regex - extract HTML tag and its content
  6. * Array map:
  7. * x[0] = everything
  8. * x[1] = open tag
  9. * x[2] = attributes
  10. * x[3] = content & end tag
  11. * x[4] = content only
  12. *
  13. * Note for content: including text node + children node
  14. */
  15. $reg = '/(<'.$el.'(.*?)>)((n*?.*?n*?)</'.$el.'>|)/';
  16.  
  17. if (preg_match($reg, $html_str, $match)) { echo 'Moving onward!';}
  18.  
  19. $dom = new DomDocument();
  20. $content = mb_convert_encoding(
  21. get_the_content(null, true), # WordPress func, it gives input str
  22. 'HTML-ENTITIES',
  23. 'UTF-8'
  24. );
  25. $dom->loadHTML($content);
  26.  
  27. $el = $doc->getElementsByTagName('li');
  28.  
  29. <link rel="stylesheet" href="/html_5/tags/html_link_tag_example.css">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement