wp_kses_hair_parse

函式
wp_kses_hair_parse ( $attr )
引數
  • (string) $attr Attribute list from HTML element to closing HTML element tag.
    Required:
返回值
  • (array|false) List of attributes found in $attr. Returns false on failure.
定義位置
相關方法
wp_kses_attr_parsewp_kses_hairwp_kses_attrwp_kses_datawp_kses_attr_check
引入
4.2.3
棄用
-

wp_kses_hair_parse: 這個函式用來解析一個HTML標籤,並將其屬性與內容分開。

從包含屬性的字串中建立一個屬性列表。

不修改輸入。 可能會返回””evil”” 輸出。如果有意外的輸入,返回false,而不是剝離東西。

基於 `wp_kses_hair()` 但不返回多維陣列。

function wp_kses_hair_parse( $attr ) {
	if ( '' === $attr ) {
		return array();
	}

	// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
	$regex =
		'(?:'
		.     '[_a-zA-Z][-_a-zA-Z0-9:.]*' // Attribute name.
		. '|'
		.     '[[?[^[]]+]]?'        // Shortcode in the name position implies unfiltered_html.
		. ')'
		. '(?:'               // Attribute value.
		.     's*=s*'       // All values begin with '='.
		.     '(?:'
		.         '"[^"]*"'   // Double-quoted.
		.     '|'
		.         "'[^']*'"   // Single-quoted.
		.     '|'
		.         '[^s"']+' // Non-quoted.
		.         '(?:s|$)'  // Must have a space.
		.     ')'
		. '|'
		.     '(?:s|$)'      // If attribute has no value, space is required.
		. ')'
		. 's*';              // Trailing space is optional except as mentioned above.
	// phpcs:enable

	// Although it is possible to reduce this procedure to a single regexp,
	// we must run that regexp twice to get exactly the expected result.

	$validation = "%^($regex)+$%";
	$extraction = "%$regex%";

	if ( 1 === preg_match( $validation, $attr ) ) {
		preg_match_all( $extraction, $attr, $attrarr );
		return $attrarr[0];
	} else {
		return false;
	}
}

常見問題

FAQs
檢視更多 >