extract_from_markers( string $filename, string $marker )

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


Description Description


Parameters Parameters

$filename

(string) (Required)

$marker

(string) (Required)


Top ↑

Return Return

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


Top ↑

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 ) {
			$result[] = $markerline;
		}
		if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) {
			$state = true;
		}
	}

	return $result;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.