PHP here document, PHP Here document Tutorial
Posted on: April 14, 2006 at 12:00 AM
PHP also has the Here Document output style. It allows you to embed text data in your script.

PHP "Here document" output style

For those cases where you need to set in your PHP script a string containing big chunk of text data (for example, HTML code), it is easier to use "here document" style. This special way allows you to set multiline strings, with all included variables expanded as it is done in double quotes style.
Lets view this code:

$str = <<<HERE_NAME
Example of here document
style for setting big chunks of text data
in your script
HERE_NAME;

The label HERE_NAME that stands after <<< is called "here document" label. After "here document" line, all text will be set into the string including space and carriage return symbols. The output ends when the single line with "here document" label is found. In the example above, output ends on the line with HERE_NAME label.

If your code with heredoc lines does not work, you should look for these most common mistakes:
· HERE_NAME label must contain only alphanumeric characters and underscores, and it should not start with a digit character or underscore.
· After ending HERE_NAME label there should be only ; and \n symbols as they can be written in UNIX text editors
This style of output is very useful for writing CGI scripts.

Example of PHP Here document
<?php

$name = "Deepak Kumar";
$occupation = "Programmer";
$lognText = <<<EOF

This is a heredoc section.
For more information talk to $name, your local $occupation.

Thanks!

EOF;


echo strtolower($lognText);

?>
Output:
This is a heredoc section.
For more information talk to Deepak Kumar, your local Programmer.

Thanks!

 

More Tutorials on roseindia.net for the topic PHP here document, PHP Here document Tutorial.
PHP here document, PHP Here document Tutorial
is very useful for writing CGI scripts. Example of PHP Here document <...PHP "Here document" output style For those cases where you need...;<<HERE_NAME Example of here document style for setting big chunks
 
PHP Tutorial
on roseindia.net PHP Tutorial (adsbygoogle = window.adsbygoogle || []).push...PHP Tutorial  Hi, I am looking for PHP tutorials on roseindia.net. Provide me the urls of PHP tutorials? Thanks (adsbygoogle
 
php
and Solaris. To know more about PHP, Visit Here...php  what is php   PHP is one of the most used open source server-side scripting language, which runs on almost all the platform. PHP
 
PHP Ajax tutorial
PHP Ajax tutorial  Hi, I am learning Ajax with PHP. Provide me few examples of Ajax with PHP. Thanks   Hi, Here are few tutorials: PHP Ajax and Database Getting Started with Ajax Thanks
 
New features in PHP 5.5
TutorialsADS_TO_REPLACE_12 Here are the top Tutorials of PHP: PHP Tutorial Starting... to a flat file database (text document) using this tutorial   PHP... applications. Here are the important features of PHP 5.5 1. GeneratorsADS_TO_REPLACE_1
 
Get Variable in PHP Video tutorial
In this tutorial you will learn to use GET variable in PHP with the help... GET variable in PHP as the tutorial has been described with simple example... with the tutorial you will finally know about how to use GET variable in PHP easily and can
 
PHP Working with Variables Tutorial
; If you are planning to start writing in PHP you should  know what a variable is and how to use a variable.. Here is an example of a variable: $jim = "... is this: _ ). Here is an example of proper syntax This name would not be allowed: $stea7th
 
PHP File Manipulation File existance checking Tutorial, PHP check file exists
=/images/file1.jpg; file_exists($DOCUMENT_ROOT.$TmpName); where $DOCUMENT_ROOT - PHP... should use file exists PHP function. Syntax: file_exists($path), where... root path. Here is the code that checks file named file1.jpg in "
 
PHP Introduction to PHP Echo and print Tutorial
Ok, this is a basic tutorial to help people just getting started with PHP. In this tutorial I will show you how to output to the webpage. We will use two... things first: all newcomers to PHP will be happy to know that PHP code can
 
Example of fgetc in PHP, fgetc php, fgetc in php
Learn how to use the fgetc() function in PHP programming. SyntaxADS... the loopADS_TO_REPLACE_3 For example @sign,© sign, .sign etc. Here users... will be one character in single lineADS_TO_REPLACE_4 Code for PHP fgetc
 
PHP Tutorial
PHP Tutorial  Hi, I am new in PHP programming. Can anyone provide me good urls to learn PHP? Thanks   Hi, Start learning PHP at PHP Tutorial section. Thanks
 
PHP Basics, PHP Basics tutorials for beginners
tutorial we have covered the following topics: What is PHP: In this topic...: This PHP tutorial will help or guide you to download and install PHP step by step... and print language construct.   Introduction to PHP array: This tutorial
 
What's PHP ?
What's PHP ?  What's PHP ?   Hi friends, PHP stands... developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. Basic syntax: A PHP
 
PHP
of the page into web browser. Here is the simple example of PHP that prints "...PHP PHP stands for Hypertext Preprocessor; PHP is server-side scripting language for development of web applications. PHP powerful and robust programming
 
HTML Forms and PHP
Here we would integrate the HTML forms and PHP by creating HTML forms... of which PHP document will process the results of the form. A document... want here is “text” or a text box (we could also have a radio
 
PHP Installing PHP LAMP - Linux Apache MySQL and PHP Tutorial
PHP Installing PHP LAMP - Linux Apache MySQL and PHP Tutorial In this tutorial we will learn how to install Linux, Apache, MySQL and PHP. This guide... you in doing so. Here is the steps to install Apache, MySQL and PHP using yum
 
Php frameworks
Php frameworks  What are the best framework in php to learn and work on? I know Smarty only.   Please visit the following link: PHP Tutorials Here you will find several php tutorials with good illustration
 
PHP Get Base Directory
PHP Get Base Directory  To know the base directory we may use $_SERVER['DOCUMENT_ROOT']; Code:ADS_TO_REPLACE_1 <?php //to know your base directory ADS_TO_REPLACE_2 print ($_SERVER['DOCUMENT_ROOT']); ?>  ADS
 
php include
php include  i'm trying to include a header on my page but it doesn't display anything here's my code
 
PHP Hello Video Tutorial for Beginners
://localhost/tutorial/helloworld.php in your browser. Here the video of the "PHP...Learn PHP Hello Video Tutorial - for beginners This PHP Hello video tutorial... in PHP. This is very basic tutorial which displays "Hello World" message
 
PHP Training course - Online and classroom PHP training
of PHP scripting language. Here is the video tutorial of "PHP Training Course... web pages and thus it has gained so much of popularity. Here we offer PHP...PHP Training course - Online and classroom PHP training PHP was designed
 
PHP File Manipulation Writing to a File Tutorial
(text document) using this tutorial.  In PHP, we can do many things...: http://roseindia.net/tutorial/php/phpbasics/tutorial/PHP-File-Handling.html... File Manipulation in PHP      
 
Create a directory in php
Creating a directory in php In  this example, you will learn to create a form in HTML and call php action function of creating directory in HTML form. For this, first create an action form in HTML and call the php function
 
PHP vs J2EE, PHP vs JAVA
PHP Vs Java Those who think that java scales and PHP not is wrong, PHP... is easy-to-write, easy-maintain, cross-platform, scalable PHP platform... Performance Both PHP and Java runs on virtual machine. Java beat PHP on some
 
Sql Examples using php code
Here is the many examples. In this tutorial we discuss many examples of sql statements using php code
 
Creating Blank DOM Document
Creating Blank DOM Document       This tutorial shows you how to create blank DOM document. JAXP... approach to Parsing XML documents. With JAXP, we will use the Document
 
Javascript and PHP
Javascript and PHP  Hello, I want to know how to call javascript function inside PHP code . Could you please tell me the way to call it? Thanks   Here is a simple example of php that calls javascript function. <
 
PHP, PHP Tutorials, Free PHP Tutorials
a comprehensive feature of coding. In our free PHP tutorial, you will find all the relevant topics related to basic programming. Our PHP tutorial is full of running...: Installing WAMP Server PHP Hello Video Tutorial for Beginners What you'll need
 
PHP Files management functions and examples.
program. Here in this section we will learn about all the PHP file functions.ADS... The PHP file management is import in any application development... to read the some data from the file and display on the users browser. PHP scripting
 
PHP Functions, PHP Functions Tutorials
programming easily and rapidly.ADS_TO_REPLACE_2 Here are the list of important PHP...PHP Functions In this section we will understand important PHP functions... Here is an example of custom function: function validateUser($username
 
PHP line break, PHP nl2br() function
. Here is the syntax of the nl2br() tag: ADS_TO_REPLACE_2 <?php... Welcome to the PHP programming.<br /> <br /> Here you will learn PHP... The PHP Line break example & code If you are developing the application
 
Sitemap PHP Tutorial
Questions | Site Map | Business Software Services India PHP Tutorial... Tutorial Section Why PHP Is So Useful | Evolution of PHP for Scripting Needs... Tutorial Section - IIADS_TO_REPLACE_2 PHP Beginners Guide | About PHP | PHP
 
For Loop/PHP
or do/while loop?   PHP Factorial Example: <?php $n = 5; $i = 1; $f...;Here is a java example that finds the factorial of a number. public class math
 
PHP Installation, Installing PHP on windows
than 20 minutes. Let's start the PHP installation Here is the quick steps... at http://roseindia.net/tutorial/php/phpbasics/Downloading-Installing-Wamp.html....://roseindia.net/tutorial/php/phpbasics/Running-Testing-Wamp.html In this section you
 
PHP Array
to stored values in key value pair. Here is simple example of PHP array: $fruit...PHP Array In this page we will learn about PHP Array. We will also understand how to use PHP Array in your PHP program. The PHP Array is very useful
 
jQuery tutorial for beginners with examples
in the block.ADS_TO_REPLACE_6 $(document).ready(function(){ // Your code here... along with JSP, Servlets, ASP, PHP, CGI and other languages. jQuery Hello World example:ADS_TO_REPLACE_2 Here we will create out first Hello world example
 
Complete php tutorial
Learn PHP at PHP - Hypertext Preprocessor tutorial page. Thanks...Complete php tutorial  Hi, I am trying to find the url to learn complete PHP in easily. Can some one provide me url for complete php tutorials
 
About PHP
at free of cost. The original name of PHP was Personal Home Page. This tutorial.... In this tutorial, you will learn all the fundamental theory of PHP... PHP is a widely used powerful scripting language basically used for creating
 
ppt php tutorial
ppt php tutorial  How can i work with ppt files in PHP
 
PHP Tutorials from RoseIndia
document) using this tutorial   PHP displaying the time and date into your... in PHP. Top Tutorials of PHPADS_TO_REPLACE_1 PHP Tutorial Starting PHP PHP... Starting PHP Learn the basics of PHP with this quick and simple tutorial
 
PHP Training
, with a particular study of MySQL ADS_TO_REPLACE_1 Here is the video tutorial...PHP Training     PHP is a widely... that is available free under PHP license and can be run on most of the operating
 
PHP Training In Delhi
_TO_REPLACE_1 Here is the topics included in PHP Training: Basics of PHP...PHP Training In Delhi If you looking for getting trained in PHP in Delhi, then join our PHP Training course which is provided at our office in Delhi. We
 
Best PHP tutorial for beginners
Best PHP tutorial for beginners  Hi Friends, I want to learn PHP... PHP from beginning. PHP Tutorial index page. You find good tutorials... MySQL Tutorial index page. Above tutorials will help you in learning PHP from
 
PHP Form
PHP Form In this tutorial you will learn how to pass any data from a html page to a php file, and how to use all those data. To do this we need at least two files one is html file and a php file. Here's the given example
 
PHP File based guestbook, PHP Guestbook
File based guestbook In this tutorial we will create a file based PHP guestbook in this tutorial. I have decided to put everything into one executable file... here. Now I placed all this code into one file. File gb.php <? $gbfile
 
PHP Outsourcing
PHP Outsourcing Are you looking for an outstanding and user-friendly web application based on PHP language? Your search ends here. In Roseindia... team of php developers who have developed many offshore web projects
 
php - Ajax
; here the result
 
Array length in PHP - PHP
Array length in PHP  a function to get the array length in PHP.  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phparray/php-array-length-for.html Thanks
 
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
 
Create Directory in PHP
Create Directory in PHP  Hi, I want to create a small php program like how to create directory in PHP. I need the help of PHP programmer, who could.... Thanks,   Hi, For creating Directory in PHP is not so tough task. I
 
Ads

Related Tags for PHP here document, PHP Here document Tutorial:


Ads

 
Advertisement null

Ads