extract_from_markers

Advertisement

Summery Summery

Extracts strings from between the BEGIN and END markers in the .htaccess file.

Syntax Syntax

extract_from_markers( string $filename, string $marker )

Parameters Parameters

$filename

(Required) Filename to extract the strings from.

$marker

(Required) The marker to extract the strings from.

Return Return

(string[]) An array of strings from a file (.htaccess) from between BEGIN and END markers.

Source Source

File: wp-admin/includes/misc.php

function extract_from_markers( $filename, $marker ) {
	$result = array();

	if ( ! file_exists( $filename ) ) {
		return $result;
	}

	$markerdata = explode( "\n", implode( '', file( $filename ) ) );

	$state = false;
	foreach ( $markerdata as $markerline ) {
		if ( false !== strpos( $markerline, '# END ' . $marker ) ) {
			$state = false;
		}
		if ( $state ) {
			if ( '#' === substr( $markerline, 0, 1 ) ) {
				continue;
			}
			$result[] = $markerline;
		}
		if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) {
			$state = true;
		}
	}

	return $result;
}

Advertisement

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Advertisement

Leave a Reply