generate-api-docs.php
function insertWithMarkers( $filename, $insertion ) {

		if ( ! is_array( $insertion ) ) {
			$insertion = explode( "\n", $insertion );
		}

		if ( ! file_exists( $filename ) || is_writable( $filename ) ) {
			if ( ! file_exists( $filename ) ) {
				$markerdata = '';
			} else {
				$markerdata = explode( "\n", implode( '', file( $filename ) ) );
			}

			if ( !$f = @fopen( $filename, 'w' ) )
				return false;

			$foundit = false;
			if ( $markerdata ) {

				$state = true;

				foreach ( $markerdata as $n => $markerline ) {
					if (strpos($markerline, $this->start_marker) !== false) {
						$state = false;
					}

					if ( $state ) {
						if ( $n + 1 < count( $markerdata ) )
							fwrite( $f, "{$markerline}\n" );
						else
							fwrite( $f, "{$markerline}" );
					}

					if ( strpos( $markerline, $this->end_marker ) !== false) {
						fwrite( $f, $this->start_marker . "\n" );

						if ( is_array( $insertion ) ) {
							foreach ( $insertion as $insertline ) {
								fwrite( $f, "{$insertline}\n" );
							}
						}

						fwrite( $f, $this->end_marker . "\n" );
						$state = true;
						$foundit = true;
					}
				}
			}
			if ( ! $foundit ) {
				fwrite( $f, "\n" . $this->start_marker . "\n" );
				foreach ( $insertion as $insertline ) {
					fwrite( $f, "{$insertline}\n" );
				}
				fwrite( $f, $this->end_marker . "\n" );
			}

			fclose( $f );
			return true;

		}

		return false;

	}
function insertWithMarkers( $filename, $insertion ) {

		if ( ! is_array( $insertion ) ) {
			$insertion = explode( "\n", $insertion );
		}

		if ( ! file_exists( $filename ) || is_writable( $filename ) ) {
			if ( ! file_exists( $filename ) ) {
				$markerdata = '';
			} else {
				$markerdata = explode( "\n", implode( '', file( $filename ) ) );
			}

			if ( !$f = @fopen( $filename, 'w' ) )
				return false;

			$foundit = false;
			if ( $markerdata ) {

				$state = true;

				foreach ( $markerdata as $n => $markerline ) {
					if (strpos($markerline, $this->start_marker) !== false) {
						$state = false;
					}

					if ( $state ) {
						if ( $n + 1 < count( $markerdata ) )
							fwrite( $f, "{$markerline}\n" );
						else
							fwrite( $f, "{$markerline}" );
					}

					if ( strpos( $markerline, $this->end_marker ) !== false) {
						fwrite( $f, $this->start_marker . "\n" );

						if ( is_array( $insertion ) ) {
							foreach ( $insertion as $insertline ) {
								fwrite( $f, "{$insertline}\n" );
							}
						}

						fwrite( $f, $this->end_marker . "\n" );
						$state = true;
						$foundit = true;
					}
				}
			}
			if ( ! $foundit ) {
				fwrite( $f, "\n" . $this->start_marker . "\n" );
				foreach ( $insertion as $insertline ) {
					fwrite( $f, "{$insertline}\n" );
				}
				fwrite( $f, $this->end_marker . "\n" );
			}

			fclose( $f );
			return true;

		}

		return false;

	}
Inserts an array of strings into a file (.htaccess ), placing it between
BEGIN and END markers. Replaces existing marked info. Retains surrounding
data. Creates file if none exists.

@author  Unknown. Adapted from WordPress core.

@param string $filename
@param string $marker
@param string|array $insertion
@return bool True on write success, false on failure.