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标记之间提取字符串。

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
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2026-01-29 11:09:38

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: