deslash

函式
deslash ( $content )
引數
  • (string) $content The content to modify.
    Required:
返回值
  • (string) The de-slashed content.
定義位置
相關方法
wp_slashwp_unslashaddslashes_gpcdbdeltabackslashit
引入
1.5.0
棄用
-

deslash是一個WordPress的函式,可以從一個字串或一個字串陣列中刪除斜線: 這個函式在處理從表單中提交的資料時非常有用,在這些資料中可能已經新增了斜線以防止某些字元破壞表單。

內容的過濾器,刪除不必要的斜線。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >