Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!