「PHP」 addslashes ()関数で文字列をスラッシュでクォートするサンプル

説明
addslashes ( string $str ) : string
エスケープすべき文字の前にバックスラッシュを付けて返します。 エスケープすべき文字とは、以下のとおりです。
シングルクォート (')
ダブルクォート (“)
バックスラッシュ (\)
NUL (NULL バイト)
PHPコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$strA = "あいうえお 'TO' 1 23456";
$strB = "study 'php' and become 'strong'";
echo addslashes($strA)."<br>\n";
echo addslashes($strB)."<br>\n";
?>
<?php $strA = "あいうえお 'TO' 1 23456"; $strB = "study 'php' and become 'strong'"; echo addslashes($strA)."<br>\n"; echo addslashes($strB)."<br>\n"; ?>
<?php
$strA = "あいうえお 'TO' 1 23456";

$strB = "study 'php'  and become 'strong'";
echo addslashes($strA)."<br>\n"; 
echo addslashes($strB)."<br>\n"; 
?>

実行結果
あいうえお \’TO\’ 1 23456
study \’php\’ and become \’strong\’

PHP

Posted by arkgame