backslashit() WordPress Function

The backslashit() function is a utility function that helps to escape strings for use in various contexts. It is especially useful for escaping strings that contain special characters that need to be escaped for use in regular expressions or in HTML attributes.

backslashit( string $string ) #

Adds backslashes before letters and before a number at the start of a string.


Parameters

$string

(string)(Required)Value to which backslashes will be added.


Top ↑

Return

(string) String with backslashes inserted.


Top ↑

Source

File: wp-includes/formatting.php

function backslashit( $string ) {
	if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' ) {
		$string = '\\\\' . $string;
	}
	return addcslashes( $string, 'A..Za..z' );
}

Top ↑

Changelog

Changelog
VersionDescription
0.71Introduced.

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.

Show More