deslash() WordPress Function

The deslash() function is a utility function that strips backslashes from a string. This is useful when you need to store data in a database that doesn't support backslashes, or when you want to remove backslashes from user input before displaying it on a page.

deslash( string $content ) #

Filters for content to remove unnecessary slashes.


Parameters

$content

(string)(Required)The content to modify.


Top ↑

Return

(string) The de-slashed content.


Top ↑

Source

File: wp-admin/includes/upgrade.php

function deslash( $content ) {
	// Note: \\\ inside a regex denotes a single backslash.

	/*
	 * Replace one or more backslashes followed by a single quote with
	 * a single quote.
	 */
	$content = preg_replace( "/\\\+'/", "'", $content );

	/*
	 * Replace one or more backslashes followed by a double quote with
	 * a double quote.
	 */
	$content = preg_replace( '/\\\+"/', '"', $content );

	// Replace one or more backslashes with one backslash.
	$content = preg_replace( '/\\\+/', '\\', $content );

	return $content;
}

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.