wppaste
WordPress

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

Since
2.9.0, 3.0.0
Source
wp-includes/class-wp-oembed.php:758
Strips any new lines from the HTML.

Compatibility

WordPress
since 3.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$htmlstring
Existing HTML.
$dataobject
Data object from WP_oEmbed::data2html()
$urlstring
The original URL passed to oEmbed.

Return value

string
Possibly modified $html

Performance profile

How much work a call to WP_oEmbed::_strip_newlines() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
6–33

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 51.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • regexregular expression over the whole inputpreg_match_all()called directly

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_oEmbed::_strip_newlines() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$html6none
$html32–33preg_match_all(), array_values(), array_keys()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev516–333
8.5516–333
8.4516–33321 fewer instructions than PHP 8.3
8.3729–513
8.2729–513
8.1729–513
7.4729–513

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 1

  • str_contains()Polyfill for `str_contains()` function added in PHP 8.0.

Source code

	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 );	}

Changelog

Introduced in 3.0.0. 2 changes between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.7
Parameter $html retyped from string to string|false.verified against source
6.9.7
Return type changed from string to string|false.verified against source
3.0.0
from the docblock
2.9.0
as strip_scribd_newlines()from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-oembed.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.