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

_deep_replace() WordPress Function

The deep_replace() function is a powerful tool for replacing text in a WordPress site. This function can be used to replace text in the content, titles, and even in the database. deep_replace() is a versatile function that can be used to perform a wide range of text replacements.

_deep_replace( string|array $search, string $subject ) #

Performs a deep string replace operation to ensure the values in $search are no longer present.


Description

Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values e.g. $subject = ‘%0%0%0DDD’, $search =’%0D’, $result =” rather than the ‘%0%0DD’ that str_replace would return


Top ↑

Parameters

$search

(string|array)(Required)The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.

$subject

(string)(Required)The string being searched and replaced on, otherwise known as the haystack.


Top ↑

Return

(string) The string with the replaced values.


Top ↑

Source

File: wp-includes/formatting.php

function _deep_replace( $search, $subject ) {
	$subject = (string) $subject;

	$count = 1;
	while ( $count ) {
		$subject = str_replace( $search, '', $subject, $count );
	}

	return $subject;
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More