Title: WP_HTML_Tag_Processor::subdivide_text_appropriately
Published: February 24, 2026
Last modified: August 20, 2026

---

# WP_HTML_Tag_Processor::subdivide_text_appropriately(): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#changelog)

Subdivides a matched text node, splitting NULL byte sequences and decoded whitespace
as distinct nodes prefixes.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#description)󠁿

Note that once anything that’s neither a NULL byte nor decoded whitespace is encountered,
then the remainder of the text node is left intact as generic text.

 * The HTML Processor uses this to apply distinct rules for different kinds of text.
 * Inter-element whitespace can be detected and skipped with this method.

Text nodes aren’t eagerly subdivided because there’s no need to split them unless
decisions are being made on NULL byte sequences or whitespace-only text.

Example:

    ```php
    $processor = new WP_HTML_Tag_Processor( "\x00Apples & Oranges" );
    true  === $processor->next_token();                   // Text is "Apples & Oranges".
    true  === $processor->subdivide_text_appropriately(); // Text is "".
    true  === $processor->next_token();                   // Text is "Apples & Oranges".
    false === $processor->subdivide_text_appropriately();

    $processor = new WP_HTML_Tag_Processor( "&#xD; \r\n\tMore" );
    true  === $processor->next_token();                   // Text is "␍ ␊␉More".
    true  === $processor->subdivide_text_appropriately(); // Text is "␍ ␊␉".
    true  === $processor->next_token();                   // Text is "More".
    false === $processor->subdivide_text_appropriately();
    ```

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#return)󠁿

 bool Whether the text node was subdivided.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#source)󠁿

    ```php
    public function subdivide_text_appropriately(): bool {
    	if ( self::STATE_TEXT_NODE !== $this->parser_state ) {
    		return false;
    	}

    	$this->text_node_classification = self::TEXT_IS_GENERIC;

    	/*
    	 * NULL bytes are treated categorically different than numeric character
    	 * references whose number is zero. `&#x00;` is not the same as `"\x00"`.
    	 */
    	$leading_nulls = strspn( $this->html, "\x00", $this->text_starts_at, $this->text_length );
    	if ( $leading_nulls > 0 ) {
    		$this->token_length             = $leading_nulls;
    		$this->text_length              = $leading_nulls;
    		$this->bytes_already_parsed     = $this->token_starts_at + $leading_nulls;
    		$this->text_node_classification = self::TEXT_IS_NULL_SEQUENCE;
    		return true;
    	}

    	/*
    	 * Start a decoding loop to determine the point at which the
    	 * text subdivides. This entails raw whitespace bytes and any
    	 * character reference that decodes to the same.
    	 */
    	$at  = $this->text_starts_at;
    	$end = $this->text_starts_at + $this->text_length;
    	while ( $at < $end ) {
    		$skipped = strspn( $this->html, " \t\f\r\n", $at, $end - $at );
    		$at     += $skipped;

    		if ( $at < $end && '&' === $this->html[ $at ] ) {
    			$matched_byte_length = null;
    			$replacement         = WP_HTML_Decoder::read_character_reference( 'data', $this->html, $at, $matched_byte_length );
    			if ( isset( $replacement ) && 1 === strspn( $replacement, " \t\f\r\n" ) ) {
    				$at += $matched_byte_length;
    				continue;
    			}
    		}

    		break;
    	}

    	if ( $at > $this->text_starts_at ) {
    		$new_length                     = $at - $this->text_starts_at;
    		$this->text_length              = $new_length;
    		$this->token_length             = $new_length;
    		$this->bytes_already_parsed     = $at;
    		$this->text_node_classification = self::TEXT_IS_WHITESPACE;
    		return true;
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/html-api/class-wp-html-tag-processor.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/html-api/class-wp-html-tag-processor.php#L3723)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/html-api/class-wp-html-tag-processor.php#L3723-L3776)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTML_Decoder::read_character_reference()](https://developer.wordpress.org/reference/classes/wp_html_decoder/read_character_reference/)`wp-includes/html-api/class-wp-html-decoder.php` |

Attempt to read a character reference at the given location in a given string, depending on the context in which it’s found.

  |

| Used by | Description | 
| [WP_HTML_Processor::step()](https://developer.wordpress.org/reference/classes/wp_html_processor/step/)`wp-includes/html-api/class-wp-html-processor.php` |

Steps through the HTML document and stop at the next tag, if any.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/subdivide_text_appropriately/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_html_tag_processor%2Fsubdivide_text_appropriately%2F)
before being able to contribute a note or feedback.