extract_from_markers() WordPress Function

This function allows you to extract content from HTML tags. It takes two parameters: the first is the string of HTML code you want to search, and the second is the string of the HTML tag you're looking for. The function will then return an array of all the content between those tags.

extract_from_markers( string $filename, string $marker ) #

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


Parameters

$filename

(string)(Required)Filename to extract the strings from.

$marker

(string)(Required)The marker to extract the strings from.


Top ↑

Return

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


Top ↑

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;
}

Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.