wp_kses_attr_parse

Finds all attributes of an HTML element.

Description

(array|bool) wp_kses_attr_parse( (string) $element ); 

Does not modify input. May return evil output.

Based on wp_kses_split2() and wp_kses_attr()

Returns (array|bool)

List of attributes found in $element. Returns false on failure.

Parameters (1)

0. $element (string)
HTML element/tag

Usage

  1. if ( !function_exists( 'wp_kses_attr_parse' ) ) { 
  2. require_once ABSPATH . WPINC . '/kses.php'; 
  3.  
  4. // HTML element/tag 
  5. $element = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_kses_attr_parse($element); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/kses.php  
  1. function wp_kses_attr_parse( $element ) { 
  2. $valid = preg_match('%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches); 
  3. if ( 1 !== $valid ) { 
  4. return false; 
  5.  
  6. $begin = $matches[1]; 
  7. $slash = $matches[2]; 
  8. $elname = $matches[3]; 
  9. $attr = $matches[4]; 
  10. $end = $matches[5]; 
  11.  
  12. if ( '' !== $slash ) { 
  13. // Closing elements do not get parsed. 
  14. return false; 
  15.  
  16. // Is there a closing XHTML slash at the end of the attributes? 
  17. if ( 1 === preg_match( '%\s*/\s*$%', $attr, $matches ) ) { 
  18. $xhtml_slash = $matches[0]; 
  19. $attr = substr( $attr, 0, -strlen( $xhtml_slash ) ); 
  20. } else { 
  21. $xhtml_slash = ''; 
  22.  
  23. // Split it 
  24. $attrarr = wp_kses_hair_parse( $attr ); 
  25. if ( false === $attrarr ) { 
  26. return false; 
  27.  
  28. // Make sure all input is returned by adding front and back matter. 
  29. array_unshift( $attrarr, $begin . $slash . $elname ); 
  30. array_push( $attrarr, $xhtml_slash . $end ); 
  31.  
  32. return $attrarr;