extract_from_markers

函式
extract_from_markers ( $filename, $marker )
引數
  • (string) $filename Filename to extract the strings from.
    Required:
  • (string) $marker The marker to extract the strings from.
    Required:
返回值
  • (string[]) An array of strings from a file (.htaccess) from between BEGIN and END markers.
定義位置
相關方法
insert_with_markersget_date_from_gmtget_gmt_from_datewp_extract_urlsget_bookmarks
引入
1.5.0
棄用
-

extract_from_markers: 這個函式用來提取兩個標記之間的檔案的一個特定部分。

從.htaccess檔案中的BEGIN和END標記之間提取字串。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >