Solved

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

Posted on 2010-09-01
7
318 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

679 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