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

---

# WP_oEmbed::_strip_newlines( string|false $html, object $data, string $url ): string|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_oembed/_strip_newlines/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_oembed/_strip_newlines/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_oembed/_strip_newlines/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_oembed/_strip_newlines/?output_format=md#changelog)

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

Strips any new lines from the HTML.

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

 `$html`string|falserequired

Existing HTML.

`$data`objectrequired

Data object from [WP_oEmbed::data2html()](https://developer.wordpress.org/reference/classes/wp_oembed/data2html/)

`$url`stringrequired

The original URL passed to oEmbed.

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

 string|false Possibly modified $html.

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

    ```php
    public function _strip_newlines( $html, $data, $url ) {
    	if ( ! str_contains( $html, "\n" ) ) {
    		return $html;
    	}

    	$count     = 1;
    	$found     = array();
    	$token     = '__PRE__';
    	$search    = array( "\t", "\n", "\r", ' ' );
    	$replace   = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' );
    	$tokenized = str_replace( $search, $replace, $html );

    	preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER );
    	foreach ( $matches as $i => $match ) {
    		$tag_html  = str_replace( $replace, $search, $match[0] );
    		$tag_token = $token . $i;

    		$found[ $tag_token ] = $tag_html;
    		$html                = str_replace( $tag_html, $tag_token, $html, $count );
    	}

    	$replaced = str_replace( $replace, $search, $html );
    	$stripped = str_replace( array( "\r\n", "\n" ), '', $replaced );
    	$pre      = array_values( $found );
    	$tokens   = array_keys( $found );

    	return str_replace( $tokens, $pre, $stripped );
    }
    ```

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

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

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

## User Contributed Notes

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