SlideShare uma empresa Scribd logo
1 de 21
CONFIDENTIAL All Contents Copyright and Copy 2013; evisu0414.com All rights reserved. 1
初心者必見!
あなたはダブルクォーテーションと
シングルクォーテーションの違い
言えますか?
担当:ヱビス
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 2
name: ヱビス(evisu0414)
job:Webプログラマ兼講師
hp:http://evisu0414.com
twitter:@evisu0414
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 3
知っているようで知らない
「ダブルクォーテーション」
と
「シングルクォーテーション」
違いがあるって知ってました?
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 4
違いなんてないよ( ・´ー・`)
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 5
検証してみよう その1
■ダブルクォーテーションを使った場合
<?php
echo “Hello PHP !!”;
?>
■表示結果
> Hello PHP !!
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 6
検証してみよう その2
■シングルクォーテーションを使った場合
<?php
echo ‘Hello PHP !!’;
?>
■表示結果
> Hello PHP !!
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 7
結果一緒じゃん!( ・´ー・`)
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 8
別のデータで検証してみよう
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 9
検証してみよう その3
■ダブルクォーテーションを使った場合
<?php
$hello = “Hello PHP !!”;
echo “$hello”;
?>
■表示結果
> Hello PHP !!
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 10
検証してみよう その4
■シングルクォーテーションを使った場合
<?php
$hello = “Hello PHP !!”;
echo ‘$hello’;
?>
■表示結果
> $hello
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 11
えぇ!結果が違う(´・ω・`)
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 12
何が違うの?
・ダブルクォーテーション
PHPの変数が展開できる
変数の内容を表示することができる
・シングルクォーテーション
PHPの変数名をそのまま表示してしまう
変数の内容を表示することができない
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 13
何が違うの?
・ダブルクォーテーション
表示される際に、PHP側でいろいろな処理が動き
変数などの内容を解析したのちに表示している
→ 処理数が多いため、少し遅い
・シングルクォーテーション
囲まれた文字列を、そのまま表示している
→ 処理数が少ないため、少し速い
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 14
使い分けポイント
・ダブルクォーテーション
文字列内で変数を使用する場合
例)変数を含む文字列、explode関数の引数など
・シングルクォーテーション
文字列内で変数を使用しない場合
例)配列の添字名や決め打ちの文字列など
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 15
explode関数で
ダブルクォーテーション?
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 16
こんな罠があります
■サンプルコード
<?php
$hello = “Hello PHP!!
Hello PHP!!!!”;
$array = explode(‘¥r¥n’, $hello);
var_dump($array);
?>
※改行コードはWindowsで使用される「¥r¥n」が
使用されているものとします
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 17
罠発動!
■実行結果
array(1) {
[0]=>
string(21) "Hello PHP!
Hello PHP!"
}
本来であれば、expload関数は「改行コード」で分割
を行うのですが、うまくいかない(´・ω・`)
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 18
どゆこと?(・_・)
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 19
文字コードが認識されない!
「シングルクォーテーション」は改行コードも
「¥r¥n」という文字列の羅列として表示してしまい
改行コードとしての効力を失ってしまいます
その他にも。preg系関数の「正規表現」も注意が
必要な項目の1つです
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 20
まとめ
何気なく使っている「ダブルクォーテーション」や
「シングルクォーテーション」も、使用方法を正確
に理解しておかないと泥沼に陥る可能性がありま
す!
「あれ?正常に動いていない」と思ったら、
この辺りを疑ってみるのも解決の糸口になるかもし
れませんね
CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 21
ご清聴ありがとうございました
m(__)m

Mais conteúdo relacionado

Destaque

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Destaque (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

初心者必見!ダブルクォーテーションとシングルクォーテーションの違い言えますか?

  • 1. CONFIDENTIAL All Contents Copyright and Copy 2013; evisu0414.com All rights reserved. 1 初心者必見! あなたはダブルクォーテーションと シングルクォーテーションの違い 言えますか? 担当:ヱビス
  • 2. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 2 name: ヱビス(evisu0414) job:Webプログラマ兼講師 hp:http://evisu0414.com twitter:@evisu0414
  • 3. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 3 知っているようで知らない 「ダブルクォーテーション」 と 「シングルクォーテーション」 違いがあるって知ってました?
  • 4. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 4 違いなんてないよ( ・´ー・`)
  • 5. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 5 検証してみよう その1 ■ダブルクォーテーションを使った場合 <?php echo “Hello PHP !!”; ?> ■表示結果 > Hello PHP !!
  • 6. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 6 検証してみよう その2 ■シングルクォーテーションを使った場合 <?php echo ‘Hello PHP !!’; ?> ■表示結果 > Hello PHP !!
  • 7. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 7 結果一緒じゃん!( ・´ー・`)
  • 8. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 8 別のデータで検証してみよう
  • 9. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 9 検証してみよう その3 ■ダブルクォーテーションを使った場合 <?php $hello = “Hello PHP !!”; echo “$hello”; ?> ■表示結果 > Hello PHP !!
  • 10. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 10 検証してみよう その4 ■シングルクォーテーションを使った場合 <?php $hello = “Hello PHP !!”; echo ‘$hello’; ?> ■表示結果 > $hello
  • 11. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 11 えぇ!結果が違う(´・ω・`)
  • 12. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 12 何が違うの? ・ダブルクォーテーション PHPの変数が展開できる 変数の内容を表示することができる ・シングルクォーテーション PHPの変数名をそのまま表示してしまう 変数の内容を表示することができない
  • 13. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 13 何が違うの? ・ダブルクォーテーション 表示される際に、PHP側でいろいろな処理が動き 変数などの内容を解析したのちに表示している → 処理数が多いため、少し遅い ・シングルクォーテーション 囲まれた文字列を、そのまま表示している → 処理数が少ないため、少し速い
  • 14. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 14 使い分けポイント ・ダブルクォーテーション 文字列内で変数を使用する場合 例)変数を含む文字列、explode関数の引数など ・シングルクォーテーション 文字列内で変数を使用しない場合 例)配列の添字名や決め打ちの文字列など
  • 15. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 15 explode関数で ダブルクォーテーション?
  • 16. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 16 こんな罠があります ■サンプルコード <?php $hello = “Hello PHP!! Hello PHP!!!!”; $array = explode(‘¥r¥n’, $hello); var_dump($array); ?> ※改行コードはWindowsで使用される「¥r¥n」が 使用されているものとします
  • 17. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 17 罠発動! ■実行結果 array(1) { [0]=> string(21) "Hello PHP! Hello PHP!" } 本来であれば、expload関数は「改行コード」で分割 を行うのですが、うまくいかない(´・ω・`)
  • 18. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 18 どゆこと?(・_・)
  • 19. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 19 文字コードが認識されない! 「シングルクォーテーション」は改行コードも 「¥r¥n」という文字列の羅列として表示してしまい 改行コードとしての効力を失ってしまいます その他にも。preg系関数の「正規表現」も注意が 必要な項目の1つです
  • 20. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 20 まとめ 何気なく使っている「ダブルクォーテーション」や 「シングルクォーテーション」も、使用方法を正確 に理解しておかないと泥沼に陥る可能性がありま す! 「あれ?正常に動いていない」と思ったら、 この辺りを疑ってみるのも解決の糸口になるかもし れませんね
  • 21. CONFIDENTIAL All Contents Copyright and Copy 2012; Tendrlinks .inc All rights reserved. 21 ご清聴ありがとうございました m(__)m