WP_oEmbed::_strip_newlines()publicWP 3.0.0

Strips any new lines from the HTML.

Метод класса: WP_oEmbed{}

Хуков нет.

Возвращает

Строку. Possibly modified $html

Использование

$WP_oEmbed = new WP_oEmbed();
$WP_oEmbed->_strip_newlines( $html, $data, $url );
$html(строка) (обязательный)
Existing HTML.
$data(объект) (обязательный)
Data object from WP_oEmbed::data2html()
$url(строка) (обязательный)
The original URL passed to oEmbed.

Список изменений

С версии 3.0.0 Введена.
С версии 2.9.0 as strip_scribd_newlines()

Код WP_oEmbed::_strip_newlines() WP 6.4.3

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