OM2 Posted July 26, 2008 Share Posted July 26, 2008 I've seen this in a few places: $form=<<<form This is followed by what looks to be like a HTML form. Except, none of the quote characters are escaped like: \". I tried looking this up but can't find any meaningful results! Thanks. OM Link to comment https://forums.phpfreaks.com/topic/116706-newbie-whats-this-form/ Share on other sites More sharing options...
JasonLewis Posted July 26, 2008 Share Posted July 26, 2008 It's what is known as here document syntax. Basically it allows you to print out multiple lines of HTML without using lots of echo statements. What they are doing in what you've been reading is putting it all in a variable called $form then echoing out later. Note that you don't have to use <<<form You can use <<<html or <<<EOF or <<<ABCD As long as the closing identifier (which in your example would have been form;) needs to be the same. Example: echo <<<html Hello this is a way of echoing out lots of stuff and spacing it out so you can see it all! html; See how it has <<<html then ends with html; I've just echoed it out straight away, but you can store it in a variable. Then add more to it then echo it out. Example: $string = <<<EOF Hello this is a wicked string! EOF; $variable = "A variable that will be included!"; //NOTICE BELOW HOW I AM ADDING MORE TO THE VARIABLE $string .= <<<EOF Now I am adding more, and a variable! {$variable} EOF; //Now that we have all the information, we can echo it! echo $string; Hope that helps. Link to comment https://forums.phpfreaks.com/topic/116706-newbie-whats-this-form/#findComment-600066 Share on other sites More sharing options...
OM2 Posted July 26, 2008 Author Share Posted July 26, 2008 thanks. thats brilliant. can i stick in "'? i.e. can i have: echo <<<html Hello world This is "really" good html; let me know. thanks. actually... whats wrong with: $myVar = "first line second line third line"; echo $myVar; is the above allowed? is it the same thing? does one have an advantage over the other? Link to comment https://forums.phpfreaks.com/topic/116706-newbie-whats-this-form/#findComment-600123 Share on other sites More sharing options...
JasonLewis Posted July 26, 2008 Share Posted July 26, 2008 thanks. thats brilliant. can i stick in "'? i.e. can i have: echo <<<html Hello world This is "really" good html; let me know. thanks. Yes you can. actually... whats wrong with: $myVar = "first line second line third line"; echo $myVar; is the above allowed? Yes the above is allowed. is it the same thing? Basically, but you must escape your quotes with the one above. does one have an advantage over the other? Here document syntax allows you to leave your quotes un-escaped. You can test this out yourself and try it, it won't hurt. Just get a program like WAMP Server and try a few things out. Link to comment https://forums.phpfreaks.com/topic/116706-newbie-whats-this-form/#findComment-600150 Share on other sites More sharing options...
OM2 Posted July 26, 2008 Author Share Posted July 26, 2008 thanks for the reply. yes: i will test before i post. Link to comment https://forums.phpfreaks.com/topic/116706-newbie-whats-this-form/#findComment-600154 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.