Solved

What does the "<<<" do in PHP syntax?

Posted on 2010-09-01
7
314 Views
Last Modified: 2012-05-10
What does the "<<<" do in PHP syntax?  Why is it used?

And, yes, I did try 'Googling' and searching here in EE, but of course these special characters are completely ignored in searches, even with quotes around it --- or as a Side Question, if that's a better way to answer, how would one search in EE or Google for special characters?  I have several web resources, but am often stumped on searching special characters that I see in other's code, like "===" (which I finally figured out means "equal in value and type").

Thanks,
murach

Example Code: 

function myHeader()

{

  $myVariable = <<<EOFORM

     <html>

     <head>

     <title>Test Title .....

     ....

     </head>

   EOFORM;

   return($myVariable);

}

Open in new window

0
Comment
Question by:murach
7 Comments
 

Expert Comment

by:Korcan
ID: 33579716
Nothing.This code wrong and <<< is wrong for php.Php doesnt have <<< in operators or php syntax.

Best Regards
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33579735
Appears to be sample code, indicating your data will be replaced by the "<<<EOFORM"

0
 
LVL 4

Expert Comment

by:mpickreign
ID: 33579838
The code is correct. It opens a text stream that can cover multiple lines. For example (everything from <<<XML to XML will be stored in the var.

$string = <<<XML
<?xml version='1.0'?>
<document>
 <title>Forty What?</title>
 <from>Joe</from>
 <to>Jane</to>
 <body>
  I know that's the answer -- but what's the question?
 </body>
</document>
XML;
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:murach
ID: 33579871
I'm seeing several versions of the "<<<" on different websites (and also in our company's own "working" code.... so it wasn't 'sample' code, though granted, my example above was 'sample-ized').  
Perhaps it is a way to avoid using a Quotes?  I'll  had thought that if I found the "manual" for using that set of symbols, then I  could be on my own way to deciphering other shortcuts in the future.



    $query = <<<EOQUERY

INSERT INTO Appointments

  SET

    user_id = $in_userid,

    title = '$title',

    start_time = '$start',

    end_time = '$end',

    location = '$location',

    description = '$desc'

EOQUERY;



....



echo <<<EOHEADER

<h2 align='center'>Create New Appointment</h2>

$msg

EOHEADER;

Open in new window

0
 
LVL 4

Accepted Solution

by:
mpickreign earned 500 total points
ID: 33579922
0
 

Author Closing Comment

by:murach
ID: 33580022
Looks like "40" IS the answer, glad I asked the Question here.  THANK You, PHP expert, "mpickreign"!

NOTE to anyone who may plan to use "<<<":  Read the the details that are in the link from PHP that  "mpickreign" sent above, as there are Warnings and notes about it (placement in the first column, no other spaces/characters, etc.)

"........way to delimit strings is the heredoc syntax: <<<.    After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.
The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.  
..........."

0
 

Author Comment

by:murach
ID: 37109487
btw, Just adding a follow-up note as to where the "<<<" is named "heredoc" syntax:  it originates for Unix Syntax.

I was reading some Unix-scripting reference material and it gives the following description:
".....Some Unix shells support the concept of a "here-document," which serves essentially the same purpose as file input to a command, except that no explicit filename is involved. (In other words, the document is located "right here" in the script, not stored in an external file.) To provide input to a Unix command using a here-document, use the following syntax:
   Unix-command <<MARKER
   input line 1
   input line 2
   input line 3
   ...
   MARKER

The <<MARKER signals the beginning of the input and indicates the marker symbol to look for at the end of the input.
"

Thanks again, Experts-Exchange.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP warning 4 30
Move wordpress site 3 24
Angular - disable input field on page load 4 14
jQuery Validate 4 22
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now