Warning: Undefined array key 0 in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 406
Warning: Attempt to read property "parent" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 407
Warning: Attempt to read property "term_id" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413
Warning: Attempt to read property "cat_name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413
エスケープシーケンス
PHPでは改行やタブなど一部記号や、クォーテーション内で同一クォーテーションなどはそのまま入力することができません。 その場合はエスケープシーケンスを利用します。PHPのエスケープシーケンスとして用意されているのは以下の通りです。
| コード | 内容 |
|---|---|
| ¥n | 改行 |
| ¥’ | シングルクオーテーション |
| ¥” | ダブルクオーテーション |
| ¥t | タブ |
| ¥r | キャリッジリターン |
| ¥¥ | ¥文字 |
| ¥$ | $文字 |
| ¥( | 左括弧 |
| ¥) | 右括弧 |
| ¥[ | 左括弧 |
| ¥] | 右括弧 |
| ¥nnn | 8 進数表記 |
| ¥xnn | 16 進数表記 |
またエスケープシーケンスはダブルクォーテーション内でのみ使えます。 シングルクォーテーション内ではそのまま記号と見なされるので気を付けましょう。
ただしシングルクォーテーション内でも、シングルクォーテーションと記号の2つはエスケープすることができます。
エスケープシーケンス使用例
エスケープ使用前
そのままではダブルクォーテーション内でダブルクォーテーションは使用できません。
サンプル
cho "ダブルクォーテーション内で"ダブルクオーテーション"";
実行結果はエラーとなりました。どれがHTMLに出力すべきダブルクォーテーションか判断できないためです。
実行結果
arse error: syntax error, unexpected 'ダブルクォーテーショ' (T_STRING) in …
エスケープ使用前後
エスケープシーケンスを使うことにより、内側のダブルクォーテーションをエスケープ文字にし、HTMLソースに出力するダブルクォーテーションを明示しました。
サンプル
cho "ダブルクォーテーション内で"ダブルクォーテーション";
きちんと”ダブルクォーテーション”を出力できました。
実行結果
ブルクォーテーション内で"ダブルクォーテーション"




