Solved

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

Posted on 2010-09-01
7
313 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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