Purpose of backlslash in the following code?

15 views
Skip to first unread message

Cecil Champenois

unread,
Aug 26, 2010, 2:01:54 PM8/26/10
to PHP Group
echo "<div id=\"invoices\">";

 

Just what exactly is the purpose of the backslash, which is preceding the string, "invoices\" ? Is this some kind of escape thing? I see it all over the PHP code I see on the Internet, but no explanation. It is as if its purpose is a national secret.


 
Cecil

Joseph Williams

unread,
Aug 26, 2010, 2:04:23 PM8/26/10
to professi...@googlegroups.com
To `escape` the quotes. So that way php prints the " and doesn't treat it as if its outside the text to be printed/echo'd

Joe Williams
@mrstatic
https://www.speakservers.com

Jack Timmons

unread,
Aug 26, 2010, 2:05:55 PM8/26/10
to professi...@googlegroups.com
On Thu, Aug 26, 2010 at 1:04 PM, Joseph Williams
<joseph.s...@gmail.com> wrote:
> To `escape` the quotes. So that way php prints the " and doesn't treat it as
> if its outside the text to be printed/echo'd
>

SHHHHHHHHHH.

It's a national secret :(

The NSA's got your home wire tapped, now.

Cecil:

If you're looking at the code I sent earlier, it's a horrible,
horrible example of code.

--
Jack Timmons
@_Codeacula

Heath Aiken

unread,
Aug 26, 2010, 2:06:37 PM8/26/10
to professi...@googlegroups.com
No, definitely not a secret, but definitely timely to the recent discussions...

the ' \ ' is simply there to tell the PHP parser to treat the " as a character and render it as-is.  An alternative would be to do this:  echo '<div id="invoices">';  that is, if this wasn't 2010 and echoing out HTML markup was still acceptable...

--Heath


--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
 
For information or project assistance please visit :
http://www.360psg.com
 
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP

Cecil Champenois

unread,
Aug 26, 2010, 2:08:59 PM8/26/10
to professi...@googlegroups.com
It may be a global secret.
 
Cecil



From: Jack Timmons <code...@codeacula.com>
To: professi...@googlegroups.com
Sent: Thu, August 26, 2010 11:05:55 AM
Subject: Re: [Pro. PHP Dev.] Purpose of backlslash in the following code?

Cecil Champenois

unread,
Aug 26, 2010, 2:21:04 PM8/26/10
to professi...@googlegroups.com
Okie dokie, this is making sense, incredibly:
 
When I first looked at the below code, I only glanced at it and didn't see the <?php tag, which preceded it. Since the code is going through PHP interpretation first, then it makes sense.
 
The code originated from: http://pastebin.com/FP6L8Mdz
 
  1. <?php
  2. echo "<div id=\"invoices\">";
  3.         echo "<div class=\"report_nav\">";
  4.                 echo "<a target=\"_blank\" href=\"/invoices/charge_report_print/{$report_date}\">Print Report</a>";
  5.         echo "</div>";
  6.         echo "<h1>Daily Charge Report</h1>";
  7.         echo "<div style=\"text-align: center\">";
  8.                 echo "<h1>";
     
Cecil



From: Joseph Williams <joseph.s...@gmail.com>
To: professi...@googlegroups.com
Sent: Thu, August 26, 2010 11:04:23 AM

Subject: Re: [Pro. PHP Dev.] Purpose of backlslash in the following code?

Cecil Champenois

unread,
Aug 26, 2010, 2:21:54 PM8/26/10
to professi...@googlegroups.com
I think you are right.
 
Cecil



From: Jack Timmons <code...@codeacula.com>
To: professi...@googlegroups.com
Sent: Thu, August 26, 2010 11:05:55 AM

Subject: Re: [Pro. PHP Dev.] Purpose of backlslash in the following code?
Reply all
Reply to author
Forward
0 new messages