_deep_replace

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

Description

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

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

Returns (string)

The string with the replaced svalues.

Parameters (2)

0. $search (string|array)
The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
1. $subject (string)
The string being searched and replaced on, otherwise known as the haystack.

Usage

  1. if ( !function_exists( '_deep_replace' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // The value being searched for, otherwise known as the needle. 
  5. // An array may be used to designate multiple needles. 
  6. $search = null; 
  7.  
  8. // The string being searched and replaced on, otherwise known as the haystack. 
  9. $subject = ''; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = _deep_replace($search, $subject); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function _deep_replace( $search, $subject ) { 
  2. $subject = (string) $subject; 
  3.  
  4. $count = 1; 
  5. while ( $count ) { 
  6. $subject = str_replace( $search, '', $subject, $count ); 
  7.  
  8. return $subject;