llms_strip_prefixes( string $string, string[] $prefixes = array() )

Strips a list of prefixes from the start of a string.

Description Description

By default, strips llms_, lifterlms_, ‘llms-‘, or ‘lifterlms-‘. Other prefixes may be provided.

Will strip only the first prefix found from the list of supplied prefixes.

Top ↑

Parameters Parameters


(string) (Required) String to modify.


(string[]) (Optional) List of prefixs.

Default value: array()

Top ↑

Return Return

(string) The modified string. If no prefixes were found, the original string is returned without modification.

Top ↑

Source Source

File: includes/llms.functions.core.php

function llms_strip_prefixes( $string, $prefixes = array() ) {

	$prefixes = empty( $prefixes ) ? array( 'llms_', 'lifterlms_', 'llms-', 'lifterlms-' ) : $prefixes;

	foreach ( $prefixes as $prefix ) {
		if ( 0 === strpos( $string, $prefix ) ) {
			$string = substr( $string, strlen( $prefix ) );

			 * Most of the time we'll be using this to replace `llms_` as we don't often use `lifterlms_` for
			 * prefixing (anymore).
			 * Also, while it's probably not ever in use, this will prevent double-stripping if, for example,
			 * the string was `llms_lifterlms_something`. If we did want to strip that, the `$prefixes` should
			 * be overwritten to have both these items stripped.
			 * So once we find a prefix, we'll break the loop and return the string with the stripped prefix.

	return $string;


Top ↑

Changelog Changelog

Version Description
7.0.0 Added llms- and lifterlms- as additional default prefixes to strip.
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.