Outil de recherche WordPress pour les développeurs et auteurs de thèmes



extract_from_markers ›

Depuis1.5.0
Dépréciéen/a
extract_from_markers ( $filename, $marker )
Paramètres: (2)
  • (string) $filename Filename to extract the strings from.
    Requis: Oui
  • (string) $marker The marker to extract the strings from.
    Requis: Oui
Retourne:
  • (array) An array of strings from a file (.htaccess) from between BEGIN and END markers.
Défini(e) dans:
Codex:

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



Source

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