WP_Rewrite::preg_index() WordPress Method

The preg_index() method is a WordPress method used to find the position of a regular expression match within a string. This method is useful for finding the position of a particular word or phrase within a string of text. The preg_index() method takes two arguments: the regular expression to be matched and the string to be searched. This method returns the position of the first match, or -1 if no match is found.

WP_Rewrite::preg_index( int $number ) #

Indexes for matches for usage in preg_*() functions.


Description

The format of the string is, with empty matches property value, ‘$NUM’. The ‘NUM’ will be replaced with the value in the $number parameter. With the matches property not empty, the value of the returned string will contain that value of the matches property. The format then will be ‘$MATCHES[NUM]’, with MATCHES as the value in the property and NUM the value of the $number parameter.


Top ↑

Parameters

$number

(int)(Required)Index number.


Top ↑

Return

(string)


Top ↑

Source

File: wp-includes/class-wp-rewrite.php

	public function preg_index( $number ) {
		$match_prefix = '$';
		$match_suffix = '';

		if ( ! empty( $this->matches ) ) {
			$match_prefix = '$' . $this->matches . '[';
			$match_suffix = ']';
		}

		return "$match_prefix$number$match_suffix";
	}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.