TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-23-2008, 06:47 AM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default What is <<<

I cannot find this anywhere, I looked all over Google, PHP.net, and my vast collection of PHP books, and theres nothing.


PHP Code:
$taco = <<<lol
"Will you 'r'o'f'l' my waffle Mr. O'neal?"
lol; 
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-23-2008, 07:40 AM   #2 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

The exact meaning, i don't know.

But it's used to easily make a big string, as you can see it starts with lol, and it will end with lol which is the end of the string (lol not included).

People often use it to echo a large amount of text in one time.
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 04-23-2008, 10:56 AM   #3 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

PHP: Strings - Manual
sjaq is offline  
Reply With Quote
Old 04-23-2008, 01:47 PM   #4 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Thanks. I actually knew what it was , I more or less wanted some information on what you guys thought of it, and what the first and last line meant. Is that supposed to be specific or anything, or is it supposed to be three letters capitalized, or what is the convention?
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-23-2008, 03:26 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

The convention is that any string you use after the <<< is the same string you need to use to close it. So

PHP Code:
$szString = <<<EOF

<data>

EOF; 
will work exactly the same as

PHP Code:
$szString = <<<Skinnymarinkydinkydink

<data>

Skinnymarinkydinkydink; 
-m
delayedinsanity is offline  
Reply With Quote
Old 04-23-2008, 08:22 PM   #6 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Any security issues or reasons not to use it?

Wouldn't it be good for SQL statements...?
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-23-2008, 09:15 PM   #7 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

That is called a heredoc block and you can put in it what ever you need (from strings to php variables), without the need of escaping any quotes. It comes with a big con, though: it's slower that double quotes, and much slower than single quotes. Same security rules apply as for any string.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 04-23-2008, 10:02 PM   #8 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

The speed differences are negligible though, as with most things, unless you're writing a very intensive script. It's less than milliseconds on a regular call.

Personally I wouldn't use it for SQL statements. They can get long, but not that long. It's much more useful for blocks of HTML, or for such things as sending out a form letter email from your script.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-24-2008, 01:33 PM   #9 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
Personally I wouldn't use it for SQL statements. They can get long, but not that long.
Really? You must have never written a forum script.

I use HEREDOC quite a bit for SQL statements. The one caveat as mentioned is that the terminating string must be completely over to the left without a space or a tab.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 04-24-2008, 07:59 AM   #10 (permalink)
WebDev'n Beer Drnkn' Fool
 
stewart's Avatar
 
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
stewart is on a distinguished road
Default

Make sure to note that when ending/closing your heredoc statement, like said above, it not only needs to match the text you started it with but it needs to be on a line all by itself. That means no TABS either, nothing. Otherwise it won't recognize an end to it :)
__________________
stewart::howe
Web Developer & Programmer
CelerMedia.Com | iAmStewart.com | CelerLabs.com
Send a message via ICQ to stewart Send a message via AIM to stewart Send a message via MSN to stewart Send a message via Yahoo to stewart
stewart is offline  
Reply With Quote
Old 04-24-2008, 01:51 PM   #11 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Actually, I wrote a little one the first time I learned PHP way back when. Used a complex ID string to create a comment-style and nested threading structure, with (for then) on-the-fly ability to switch between the two quite easily. I was proud of that, never got anywhere with it because I dropped out of web development for the next 7 years, but eh.

I'm not sure how a forum script should have any longer SQL statement than any other database connected script?
-m
delayedinsanity is offline  
Reply With Quote
Old 04-24-2008, 05:08 PM   #12 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Why not just end it with >>>? I mean, that is extremely uncommon to need, and if you do need it all you need to do is escape one of the gt signs.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-24-2008, 07:01 PM   #13 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Just to give us that little rush we get when we have control.

It's basically so that if your block intends to use >>> a couple of times, you may find it easier to open and close it with the string EOF, but if your block intends to use EOF a couple times, maybe it'd be easier to open and close with >>> or whatever you wish to use. It's those little things that make people happy.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-24-2008, 07:31 PM   #14 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

would
PHP Code:
$foo = <<<>>>
//code
>>>; 
work?

and what is eof?
is the delimiter case sensitive? should it be all caps?
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-24-2008, 07:36 PM   #15 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

eof = end of line... and it's just some sort of a label when used there.
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 04-24-2008, 07:48 PM   #16 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

end of file, end of line, just habit to use that one.

And nope, using >>> won't work, I just tried it quick and it returns a parse error. The delimiter is case sensitive, and its your choice what you use. I don't think there's any real precedent for one way or the other like there is with constants vs variables, et al.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-24-2008, 08:39 PM   #17 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

It's accepted that the Heredoc identifier be all uppercase alphabetical characters, that's the convention. The rules for naming the identifier are the same as for any other label in PHP (like naming a variable): it can only contain alphanumeric characters or the underscore, with the first character being either alphabetical or underscore (ie, no numbers at the beginning).
Salathe is offline  
Reply With Quote
Old 04-27-2008, 06:21 PM   #18 (permalink)
WebDev'n Beer Drnkn' Fool
 
stewart's Avatar
 
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
stewart is on a distinguished road
Default

Usually I try to give them descriptive names...
Code:
$query =<<<SQL
   cool query..
SQL;
or
Code:
$html =<<<HTML
  sveet html..
HTML;
=)
__________________
stewart::howe
Web Developer & Programmer
CelerMedia.Com | iAmStewart.com | CelerLabs.com
Send a message via ICQ to stewart Send a message via AIM to stewart Send a message via MSN to stewart Send a message via Yahoo to stewart
stewart is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:51 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design