acf_str_replace()ACF 5.3.8

acf_str_replace

This function will replace an array of strings much like str_replace The difference is the extra logic to avoid replacing a string that has alread been replaced This is very useful for replacing date characters as they overlap with eachother

@type    function

Хуков нет.

Возвращает

$post_id. (int)

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

acf_str_replace( $string, $search_replace );
$string **
-
По умолчанию: ''
$search_replace **
-
По умолчанию: array()

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

С версии 5.3.8 Введена.

Код acf_str_replace() ACF 5.10.2

function acf_str_replace( $string = '', $search_replace = array() ) {

	// vars
	$ignore = array();

	// remove potential empty search to avoid PHP error
	unset( $search_replace[''] );

	// loop over conversions
	foreach ( $search_replace as $search => $replace ) {

		// ignore this search, it was a previous replace
		if ( in_array( $search, $ignore ) ) {
			continue;
		}

		// bail early if subsctring not found
		if ( strpos( $string, $search ) === false ) {
			continue;
		}

		// replace
		$string = str_replace( $search, $replace, $string );

		// append to ignore
		$ignore[] = $replace;

	}

	// return
	return $string;

}