extract_from_markers

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

Description

(array) extract_from_markers( (string) $filename, (string) $marker ); 

Returns (array)

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

Parameters (2)

0. $filename (string)
The filename.
1. $marker (string)
The marker.

Usage

  1. if ( !function_exists( 'extract_from_markers' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4. // The filename. 
  5. $filename = ''; 
  6.  
  7. // The marker. 
  8. $marker = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = extract_from_markers($filename, $marker); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/misc.php  
  1. function extract_from_markers( $filename, $marker ) { 
  2. $result = array (); 
  3.  
  4. if (!file_exists( $filename ) ) { 
  5. return $result; 
  6.  
  7. if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) )); 
  8. $state = false; 
  9. foreach ( $markerdata as $markerline ) { 
  10. if (strpos($markerline, '# END ' . $marker) !== false) 
  11. $state = false; 
  12. if ( $state ) 
  13. $result[] = $markerline; 
  14. if (strpos($markerline, '# BEGIN ' . $marker) !== false) 
  15. $state = true; 
  16.  
  17. return $result;