Home Techindex PHP here document, PHP Here document Tutorial

 
 

PHP here document, PHP Here document Tutorial
Posted on: April 14, 2006 at 12:00 AM
Advertisement
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
 
Creating Blank DOM Document
Creating Blank DOM Document       This tutorial shows you how to create blank DOM document. JAXP (Java... to Parsing XML documents. With JAXP, we will use the Document BuilderFactory
 
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
 
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
 
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
 
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
 
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 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 "
 
Create - XML File (Document)
Create - XML File (Document)     ... document using the DOM APIs. This XML document uses  1.0 version  and UTF-8... document on the console. This program asks for the number of elements
 
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   
 
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
 
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
 
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
 
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 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
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
 
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
 
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
 
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
 
Use Velocity to generate HTML document
Use Velocity to generate HTML document   ... document using velocity. The method used in this example are described below... is used here for merging  the VelocityContext class object 
 
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
 
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
 
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
 
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
 
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
 
Searching an Element in the given XML Document
Searching an Element in the given XML Document  ... in the specified XML document using DOM APIs defined...; the file using the parse() method. This method parses the XML document
 
Remove Element from XML Document
element from the XML document by  invoking the getParentNode() method . Here... Remove Element from XML Document     ... a given  XML document. Whenever you remove the xml element from the xml document
 
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
 
Creating a DocumentFragment Subtree and Appending it to the Document
this fragment tree to a DOM document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document... Creating a DocumentFragment Subtree and Appending it to the Document
 
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
 
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
 
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
 
include' a HTML document in another document.
include' a HTML document in another document.  I'm trying to `include' a HTML document in another document...Is there a way to do
 
Sql Examples using php code
Here is the many examples. In this tutorial we discuss many examples of sql statements using php code
 
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 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
 
open document
open document  open a word document using jsp   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
 
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
 
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 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
 
HTML document
HTML document  How do I link to a location in the middle of an HTML 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. <
 
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
 
Error here

 
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
 
Validating XML document with a DTD
Validating XML document with a DTD If an xml document is well formed i.e.... an XML document valid it must be validated, or verified, against a DTD. DTD... as valid xml document. Validation of xml is optional. If you require the xml file
 
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
 
Advertisement

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


Advertisements Advertisements
 

 

 

DMCA.com