ホームページ  >  記事  >  バックエンド開発  >  PHP はラッシュを追加します()

PHP はラッシュを追加します()

PHPz
PHPzオリジナル
2024-08-29 12:54:44936ブラウズ

addslashes() 関数は、PHP に組み込まれている事前定義された関数で、バックラッシュを含む文字列を返すために使用され、文字列内に存在するすべての事前定義された文字の前に接頭辞として付けられます。 PHP の addlashes() 関数には、関数から渡されるパラメータや引数を考慮しないという特別な特性があります。この関数では、事前定義された文字の動作が異なります。 addslashes 関数は、addcslashes() 関数と比較して多少異なります。この関数は、スラッシュの前に追加する必要がある指定された文字を受け入れるためですが、パラメーターを渡すことを許可せず、前にスラッシュを追加するため、addslashes() 関数にとっては重要ではありません。指定された文字。

無料ソフトウェア開発コースを始めましょう

Web 開発、プログラミング言語、ソフトウェア テスト、その他

構文

addslashes($string)
  • addslashes(): addslashes() 関数では、文字列の $ 記号が後に続く関数内からパラメータまたは引数を 1 つだけ渡すことができます。
  • $string : これは、addslashes 関数への入力として関数に渡される引数です。文字列を指定する属性の特別な構造を指定します。

戻り値の型: この戻り値の型は、事前に定義され、関数に文字列を追加する文字列の前に接頭辞として付けられた文字の前にバックスラッシュを付けた文字列を返します。

addslashes() 関数は PHP でどのように動作しますか?

addslashes は、スラッシュを含む引用文字列の引用符を生成する、PHP 定義の文字列参照および文字列パッケージの特別な組み込み関数です。これには、文字列内の文字が文字列の後にプレフィックスとして付加されるような特別な形式で文字列を返す戻り値の型があります:

  1. 単一引用符: 記号 (‘) で表されます
  2. ダブルクォーテーション: 記号(" ")で表します
  3. バックスラッシュ: 記号 ( ) で表します
  4. Null: (NUL バイト)
  5. で表されます。

ユースケースは、これらの文字を含む文字列の前にプレフィックスとして付けられる文字がエスケープされる文字セットであるという点で、文字列によって異なります。

この関数は、PHP バージョン 5.4.0 以降で追加され、使用されるようになりました。それ以外の場合、デフォルト値は、前述したように、文字列で使用されるすべてのタイプの GET、POST、および Cookie で magic_quotes_gpc と見なされていました。 lashes() 関数を追加します。

この関数がデータベース クエリに組み込まれると、異常に動作することがあります。したがって、PHP での addslashes 関数の使用後に確認し、対応する必要があるのは、要件の種類とバージョンによって異なります。これにより、データベースとの連携が曖昧になるため、データベース インジェクションおよびそれに関連するクエリと同期させるために発生する可能性のある状況やシナリオが発生することがあります。その際には、データベース固有のエスケープ関数またはプリペアド ステートメントを作成することが非常に必要になります。使用します。

さらに、addlashes 関数の一部として動作する、またはその一部である多くの部分文字列には、次の関数がコンパニオンとして含まれます:

  • stripcslashes(): これは、addslashes の一部としての関数で、引用符で囲まれていない文字列を生成するために使用されますが、いくつかの addcslashes で引用されます。
  • stripslashes(): これは、生成された引用符で囲まれた文字列の引用を解除する addslashes 関数の仲間でもあります。
  • addcslashes(): これは、addslashes 関数の別の部分であり、C スタイルのパターンを含む inbuild 関数で文字列を引用するという方法で、addslashes 関数と完全に補完的に機能します。
  • htmlspecialchars(): この関数は、特殊文字が HTML エンティティに変換されるように機能します。
  • Quotemeta(): この関数は、メタ文字タイプと呼ばれる文字内の文字に対して機能します。
  • get_magic_quotes_gpc(): この関数も同様に動作しますが、magic_quotes_gpc の設定の構成における現在の設定の差は非常に少なくなります。

PHP addlashes() 関数の例

以下にさまざまな例を示します:

例 #1

このプログラムは、文字列をエスケープされたシーケンスで生成された文字列の出力で表現するための addslashes 関数を表します。

コード:

<!DOCTYPE html>
<html>
<body>
<?php
$str = addslashes('hope you are doing good with educba!');
echo($str);
?>
</body>
</html>

出力:

PHP はラッシュを追加します()

Example #2

This program represents the addslashes function for the representation of the string with an output of the generated string with escaped sequences of characters but supporting the ambiguous behavior of the database injection.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
$str = "Which car is Volkswaon?";
echo $str . " It Is safe during database injection.<br>";
echo addslashes($str) . "  Safe for database injection.";
?>
</body>
</html>

Output:

PHP はラッシュを追加します()

Example #3

This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter W which behaves completely opposite of addslashes() function.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
$str = addcslashes("Welcome Educba!","W");
echo($str);
?>
</body>
</html>

Output:

PHP はラッシュを追加します()

Example #4

This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter educba for adding backslashes which behave completely opposite of addslashes() function.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
$str = "Thanks for revisiting the educba portal!";
echo $str."<br>";
echo addcslashes($str,'d')."<br>";
echo addcslashes($str,'c')."<br>";
echo addcslashes($str,'b')."<br>";
?>
</body>
</html>

Output:

PHP はラッシュを追加します()

Example #5

This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter educba for adding multiple backslashes which behaves completely opposite of addslashes() function.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
$str = "Thanks for revisiting to our portal of educba!";
echo $str."<br>";
echo addcslashes($str,'A..Z')."<br>";
echo addcslashes($str,'a..z')."<br>";
echo addcslashes($str,'a..g');
?>
</body>
</html>

Output:

PHP はラッシュを追加します()

Example #6

This program represents the HTML special characters with the elements to translate the element’s value into one value using string.

Code:

<!DOCTYPE html>
<html>
<body>
<?php
$str = "There are some good person.";
echo htmlspecialchars($str);
?>
<p>Translate into entities with HTML special characters with the elements to prevent browsers and prevent code running to display from input to the homepage</p>
</body>
</html>

Output:

PHP はラッシュを追加します()

Conclusion

The addslashes function is used to represent and traverse the string by prefixing the backslash string in front of the entire special character string and is used to quote the necessary and important string to be used simultaneously.

以上がPHP はラッシュを追加します()の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。