extract_from_markers

The timeline below displays how wordpress function extract_from_markers has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
 *
 * @since 1.5.0
 *
 * @param string $filename Filename to extract the strings from.
 * @param string $marker   The marker to extract the strings from.
 * @return string[] An array of strings from a file (.htaccess) from between BEGIN and END markers.
 */
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 (str_contains($markerline, '# END ' . $marker)) {
            $state = false;
        }
        if ($state) {
            if (str_starts_with($markerline, '#')) {
                continue;
            }
            $result[] = $markerline;
        }
        if (str_contains($markerline, '# BEGIN ' . $marker)) {
            $state = true;
        }
    }
    return $result;
}

WordPress Version: 5.4

/**
 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
 *
 * @since 1.5.0
 *
 * @param string $filename Filename to extract the strings from.
 * @param string $marker   The marker to extract the strings from.
 * @return string[] An array of strings from a file (.htaccess) from between BEGIN and END markers.
 */
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;
}

WordPress Version: 5.3

/**
 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
 *
 * @since 1.5.0
 *
 * @param string $filename Filename to extract the strings from.
 * @param string $marker   The marker to extract the strings from.
 * @return array An array of strings from a file (.htaccess) from between BEGIN and END markers.
 */
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;
}

WordPress Version: 9.1

/**
 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
 *
 * @since 1.5.0
 *
 * @param string $filename
 * @param string $marker
 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
 */
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) {
            $result[] = $markerline;
        }
        if (false !== strpos($markerline, '# BEGIN ' . $marker)) {
            $state = true;
        }
    }
    return $result;
}

WordPress Version: 4.9

/**
 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
 *
 * @since 1.5.0
 *
 * @param string $filename
 * @param string $marker
 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
 */
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) {
                $result[] = $markerline;
            }
            if (false !== strpos($markerline, '# BEGIN ' . $marker)) {
                $state = true;
            }
        }
    }
    return $result;
}

WordPress Version: 4.4

/**
 * Extracts strings from between the BEGIN and END markers in the .htaccess file.
 *
 * @since 1.5.0
 *
 * @param string $filename
 * @param string $marker
 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
 */
function extract_from_markers($filename, $marker)
{
    $result = array();
    if (!file_exists($filename)) {
        return $result;
    }
    if ($markerdata = explode("\n", implode('', file($filename)))) {
    }
    {
        $state = false;
        foreach ($markerdata as $markerline) {
            if (strpos($markerline, '# END ' . $marker) !== false) {
                $state = false;
            }
            if ($state) {
                $result[] = $markerline;
            }
            if (strpos($markerline, '# BEGIN ' . $marker) !== false) {
                $state = true;
            }
        }
    }
    return $result;
}

WordPress Version: 4.1

/**
 * {@internal Missing Short Description}}
 *
 * @since 1.5.0
 *
 * @param string $filename
 * @param string $marker
 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
 */
function extract_from_markers($filename, $marker)
{
    $result = array();
    if (!file_exists($filename)) {
        return $result;
    }
    if ($markerdata = explode("\n", implode('', file($filename)))) {
    }
    {
        $state = false;
        foreach ($markerdata as $markerline) {
            if (strpos($markerline, '# END ' . $marker) !== false) {
                $state = false;
            }
            if ($state) {
                $result[] = $markerline;
            }
            if (strpos($markerline, '# BEGIN ' . $marker) !== false) {
                $state = true;
            }
        }
    }
    return $result;
}

WordPress Version: 3.7

/**
 * {@internal Missing Short Description}}
 *
 * @since 1.5.0
 *
 * @param unknown_type $filename
 * @param unknown_type $marker
 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
 */
function extract_from_markers($filename, $marker)
{
    $result = array();
    if (!file_exists($filename)) {
        return $result;
    }
    if ($markerdata = explode("\n", implode('', file($filename)))) {
    }
    {
        $state = false;
        foreach ($markerdata as $markerline) {
            if (strpos($markerline, '# END ' . $marker) !== false) {
                $state = false;
            }
            if ($state) {
                $result[] = $markerline;
            }
            if (strpos($markerline, '# BEGIN ' . $marker) !== false) {
                $state = true;
            }
        }
    }
    return $result;
}