 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
04-23-2008, 06:47 AM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
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.
|
|
|
04-23-2008, 07:40 AM
|
#2 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
|
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? =)
|
|
|
04-23-2008, 10:56 AM
|
#3 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
|
|
|
|
04-23-2008, 01:47 PM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
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.
|
|
|
04-23-2008, 03:26 PM
|
#5 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-23-2008, 08:22 PM
|
#6 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
Any security issues or reasons not to use it?
Wouldn't it be good for SQL statements...?
__________________
Signatures are nothing but incriminating.
|
|
|
04-23-2008, 09:15 PM
|
#7 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
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.
|
|
|
|
04-23-2008, 10:02 PM
|
#8 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-24-2008, 01:33 PM
|
#9 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 154
Thanks: 31
|
Quote:
Originally Posted by delayedinsanity
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.
|
|
|
|
04-24-2008, 07:59 AM
|
#10 (permalink)
|
|
WebDev'n Beer Drnkn' Fool
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
|
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 :)
|
|
|
04-24-2008, 01:51 PM
|
#11 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-24-2008, 05:08 PM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
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.
|
|
|
04-24-2008, 07:01 PM
|
#13 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-24-2008, 07:31 PM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
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.
|
|
|
04-24-2008, 07:36 PM
|
#15 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 119
Thanks: 17
|
eof = end of line... and it's just some sort of a label when used there.
|
|
|
|
04-24-2008, 07:48 PM
|
#16 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-24-2008, 08:39 PM
|
#17 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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).
|
|
|
|
04-27-2008, 06:21 PM
|
#18 (permalink)
|
|
WebDev'n Beer Drnkn' Fool
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
|
Usually I try to give them descriptive names...
Code:
$query =<<<SQL
cool query..
SQL;
or
Code:
$html =<<<HTML
sveet html..
HTML;
=)
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|