Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

&rsquo vs "'"

I am have a question about using quotes: In the simple PHP course, Randy uses &rsquo instead of a single quote in his code; why is this preferred to using the single quote?

Just curious...

4 Answers

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Computer keyboards only have one character (') that people often use to stand in for a couple of different characters:

  • Prime symbol: ' (used in measurements like 46' to mean "feet"; notice itโ€™s straight!)
  • Apostrophe: โ€™ (notice itโ€™s curly!)

Using ’ will produce a nice curly apostrophe. Typing ' will produce a prime symbol, which is technically the wrong character to use. Most people can't tell the difference, though, and it can be a pain to type a real apostrophe if your keyboard doesn't have an apostrophe key. Imagine if keyboards didn't have the letter s on them. We'd probably all $tart typing dollar $ign$ in$tead becau$e they look pretty clo$e. Eventually, I $u$pect no one would even notice the difference between an s and a $.

Hope that help$! :~)

L0v3 ur $en$e of hum0r!

Yes, this does help, big time! And I am learning so much from your course on PHP; it enabled me to restructure my friend's website to make it more modular and easier to make global changes.

Many thanks!

Casey Ydenberg
Casey Ydenberg
15,622 Points

&rsquo will ONLY be recognized as a single quote by the browser when it's outputting the text. Single-quotes can obviously have meaning in PHP and SQL, this is ONE WAY of getting around that (there are many others).

I knew there had to be a reason for this, and thank you for answering my question. I am the kind of person who likes to know why something is a certain way, for it helps me to gain deeper insight into the underlying mechanisms and interactions that are involved.

Justin Shulman
Justin Shulman
2,903 Points

Haha had the same thought after watching the PHP course.

excellent question! thanks for answer!