Title: _split_str_by_whitespace
Published: April 25, 2014
Last modified: May 20, 2026

---

# _split_str_by_whitespace( string $text, int $goal ): array

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/functions/_split_str_by_whitespace/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Breaks a string into chunks by splitting at whitespace characters.

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

The length of each returned chunk is as close to the specified length goal as possible,
with the caveat that each chunk includes its trailing delimiter.
Chunks longer than
the goal are guaranteed to not have any inner whitespace.

Joining the returned chunks with empty delimiters reconstructs the input string 
losslessly.

Input string must have no null characters (or eventual transformations on output
chunks must not care about null characters)

    ```php
    _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234   890 123456789 1234567890a    45678   1 3 5 7 90 ", 10 ) ==
    array (
        0 => '1234 67890 ',  // 11 characters: Perfect split.
        1 => '1234 ',        //  5 characters: '1234 67890a' was too long.
        2 => '67890a cd ',   // 10 characters: '67890a cd 1234' was too long.
        3 => '1234   890 ',  // 11 characters: Perfect split.
        4 => '123456789 ',   // 10 characters: '123456789 1234567890a' was too long.
        5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split.
        6 => '   45678   ',  // 11 characters: Perfect split.
        7 => '1 3 5 7 90 ',  // 11 characters: End of $text.
    );
    ```

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_split_str_by_whitespace/?output_format=md#parameters)󠁿

 `$text`stringrequired

The string to split.

`$goal`intrequired

The desired chunk length.

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

 array Numeric array of chunks.

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

    ```php
    function _split_str_by_whitespace( $text, $goal ) {
    	$chunks = array();

    	$string_nullspace = strtr( $text, "\r\n\t\v\f ", "\000\000\000\000\000\000" );

    	while ( $goal < strlen( $string_nullspace ) ) {
    		$pos = strrpos( substr( $string_nullspace, 0, $goal + 1 ), "\000" );

    		if ( false === $pos ) {
    			$pos = strpos( $string_nullspace, "\000", $goal + 1 );
    			if ( false === $pos ) {
    				break;
    			}
    		}

    		$chunks[]         = substr( $text, 0, $pos + 1 );
    		$text             = substr( $text, $pos + 1 );
    		$string_nullspace = substr( $string_nullspace, $pos + 1 );
    	}

    	if ( $text ) {
    		$chunks[] = $text;
    	}

    	return $chunks;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/formatting.php#L3182)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L3182-L3207)

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

| Used by | Description | 
| [make_clickable()](https://developer.wordpress.org/reference/functions/make_clickable/)`wp-includes/formatting.php` |

Converts plaintext URI to HTML links.

  |

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

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

## User Contributed Notes

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