PHP here document, PHP Here document Tutorial
Posted on: April 14, 2006 at 12:00 AM
Ads
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
PHP Tutorial  Hi, I am looking for PHP tutorials on roseindia.net. Provide me the urls of PHP tutorials? Thanks   Hi, Here is the links on roseindia.net PHP Tutorial Complete PHP Tutorials Many Free PHP Tutorials
 
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
 
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
 
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
 
New features in PHP 5.5
document) using this tutorial   PHP displaying the time and date into your... applications. Here are the important features of PHP 5.5 1. Generators Now Generators... available in PHP 5.5 Here is the syntax of using the the password hashing API
 
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
 
Creating Blank DOM Document
Creating Blank DOM Document       This tutorial shows you how to create blank DOM document. JAXP... document. Document doc = parser.newDocument(); Here is the full code
 
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
 
PHP Basics, PHP Basics tutorials for beginners
way to teach PHP scripting language. In our Online Free PHP tutorial we have....    How to Download and Installing PHP: This PHP tutorial... construct.   Introduction to PHP array: This tutorial gives you
 
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
 
Example of fgetc in PHP, fgetc php, fgetc in php
Learn how to use the fgetc() function in PHP programming. Syntax string...,© sign, .sign etc. Here users have to give the new line character  If <Br> is used then result will be one character in single line Code for PHP
 
EasyEclipse for PHP
EasyEclipse for PHP       EasyEclipse for PHP contains the tools needed to start developing PHP code: the PHPEclipse IDE, some database tools, as well
 
Java Write To File Dom Document
Java Write To File Dom Document In this tutorial you will learn how to write to file dom document. Write to xml file you would be required to use the package.... Here I am giving a simple example which will demonstrate you how to write to xml
 
PHP File Manipulation Writing to a File Tutorial
(text document) using this tutorial.  In PHP, we can do many things... details please visit our web page: http://roseindia.net/tutorial/php/phpbasics/tutorial/PHP-File-Handling.html  
 
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.... Here is the steps to install Apache, MySQL and PHP using yum command
 
PHP Hello Video Tutorial for Beginners
Learn PHP Hello Video Tutorial - for beginners This PHP Hello video tutorial... in PHP. This is very basic tutorial which displays "Hello World" message.../helloworld.php in your browser. Here the video of the "PHP Hello Video
 
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
 
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
it by typing the url of the page into web browser. Here is the simple example of PHP...PHP PHP stands for Hypertext Preprocessor; PHP is server-side scripting language for development of web applications. PHP powerful and robust programming
 
Create an Empty DOM Document
documents. Here the Document BuilderFactory is used to create new DOM parsers... Create an Empty DOM Document       This Example shows how to create an empty DOM Document . JAXP
 
Sql Examples using php code
Here is the many examples. In this tutorial we discuss many examples of sql statements using php code
 
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 include
php include  i'm trying to include a header on my page but it doesn't display anything here's my code
 
PHP Training course - Online and classroom PHP training
of PHP scripting language. Here is the video tutorial of "PHP Training Course... and thus it has gained so much of popularity. Here we offer PHP online as well...PHP Training course - Online and classroom PHP training PHP was designed
 
jQuery tutorial for beginners with examples
, Servlets, ASP, PHP, CGI and other languages. jQuery Hello World example: Here.... $(document).ready(function(){ // Your code here }); The code given below...;/head> <script type="text/javascript"> $(document
 
PHP Get Base Directory
PHP Get Base Directory  To know the base directory we may use $_SERVER['DOCUMENT_ROOT']; Code: <?php //to know your base directory print ($_SERVER['DOCUMENT_ROOT']); ?>   Output: C:/wamp/www
 
Create - XML File (Document)
Create - XML File (Document)       In this section, you will  learn to create a XML document using the DOM APIs. This XML document uses  1.0 version  and UTF-8
 
Adding an Attribute in DOM Document
document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used to create new... Adding an Attribute in DOM Document   
 
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
 
The Document Object Model (DOM) APIs
The Document Object Model (DOM) APIs   ...;         The Document Object Model implementation... Document interface. The factory that creates the builder is determined
 
Listing nodes used in a document
documents. Here the Document BuilderFactory is used to create new DOM... Listing nodes used in a document       This Example shows you the Lists of nodes used in a DOM document
 
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 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... Both PHP and Java runs on virtual machine. Java beat PHP on some performance
 
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 Files management functions and examples.
program. Here in this section we will learn about all the PHP file functions.  ... 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
 
Sitemap PHP Tutorial
Questions | Site Map | Business Software Services India PHP Tutorial... by PHP  | PHP Ajax | PHP SimpleXML | PHP Ajax DB PHP Tutorial Section... Learn PHP | What a PHP Programmer Can Do PHP Beginner Tutorial Section - II
 
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 line break, PHP nl2br() function
/> Here you will learn PHP in detail So, now you can use the nl2br... The PHP Line break example & code If you are developing the application... all the occurrence of the carriage return with <br> tag. Here
 
PHP Functions, PHP Functions Tutorials
and rapidly. Here are the list of important PHP functions with explanation...PHP Functions In this section we will understand important PHP functions... may have to write code to connect to database and validate user. Here
 
JTextArea to Word Document
JTextArea to Word Document Jakarta POI has provided several classes that enable us to perform read, write operations with ms word file. Here we are going to write the data into word document file through a swing component. You can
 
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
 
Best PHP tutorial for beginners
Best PHP tutorial for beginners  Hi Friends, I want to learn PHP... Tutorial index page. You find good tutorials for learning php from beginning. Installing PHP Installing PHP LAMP PHP MySQL Tutorial index page. Above tutorials
 
Reading an XML document using JDOM
documents. Here the Document BuilderFactory is used to create new DOM parsers.These... Reading an XML document using JDOM       This Example shows you how to Read an XML document
 
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
 
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
 
PHP Tutorials from RoseIndia
in PHP. Top Tutorials of PHP PHP Tutorial Starting PHP PHP MySQL Zend... Learn the basics of PHP with this quick and simple tutorial. Designed... this tutorial   PHP displaying the time and date into your timezoneFor
 
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
 
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: userForm.html
 
Ads

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


Ads

 
Advertisement null

Ads