0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【jQuery】と【PHP】とダブルクォーテーションとシングルクォーテーションの使い分け

Posted at

要約

  1. jQueryのHTML属性:ダブルじゃないとだめな時があるgetAttribute("src")
  2. PHP:基本シングル、文字列結合するときはダブル

プロジェクトごとにルールで決まってたりするけど、結局どっちでもいいらしい

HTMLのsrc属性を取得するときにエラーが出る違いがあった
$object.getAttribute("src") // src属性が取得できる
$object.getAttribute('src') // エラーが発生する
$object.getAttribute("id") // id属性が取得できる
$object.getAttribute('id') // id属性が取得できる

細かい違いは未経験者なのでわからないが、src属性を取得しようとしたときに違いが発生。

idはどっちでもよかった
srcはダブルじゃないとダメだった

PHPはシングルの方が処理が早いとかなんとか

参考
https://pecopla.net/web-column/php-quote

シングルは早いらしい。ダブルより見やすい。

ダブルは中で変数を展開できる。

ダブルの方が便利だけど、文字列を扱う場合はシングルの方がいいみたい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?