WordPress.org

Make WordPress Core

Changeset 25054


Ignore:
Timestamp:
08/20/2013 05:56:22 AM (8 years ago)
Author:
dd32
Message:

Simplify _deep_replace() by removing it's obscure looping and replacement checking logic, and instead, using the PHP5 $count parameter of str_replace(). Props hakre. Fixes #16903

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r24986 r25054  
    25712571 * @access private
    25722572 *
    2573  * @param string|array $search
    2574  * @param string $subject
    2575  * @return string The processed string
     2573 * @param string|array $search The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
     2574 * @param string $subject The string being searched and replaced on, otherwise known as the haystack.
     2575 * @return string The string with the replaced svalues.
    25762576 */
    25772577function _deep_replace( $search, $subject ) {
    2578     $found = true;
    25792578    $subject = (string) $subject;
    2580     while ( $found ) {
    2581         $found = false;
    2582         foreach ( (array) $search as $val ) {
    2583             while ( strpos( $subject, $val ) !== false ) {
    2584                 $found = true;
    2585                 $subject = str_replace( $val, '', $subject );
    2586             }
    2587         }
     2579
     2580    $count = 1;
     2581    while ( $count ) {
     2582        $subject = str_replace( $search, '', $subject, $count );
    25882583    }
    25892584
Note: See TracChangeset for help on using the changeset viewer.