Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2010-09-01
7
317 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to read data from SQL server  to sharepoint 2013 ? 3 26
Uploading a CSV Data Import via PHP & MySql 3 33
Link failure 16 34
convert Systemjs to Webpack 3 34
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 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