Home Tutorial Php Phpbasics Tutorial PHP String Function

 
 

Share on Google+Share on Google+
PHP String Function
Posted on: March 15, 2010 at 12:00 AM
Advertisement
In this tutorial you will study about strings in PHP, different ways to print a string etc. Examples will exemplify the concept of string in PHP.

PHP String Function:

A string is nothing but a series of characters. Most easiest way to specify the string is to enclose it in single quotes (' ').

If we need to specify a string literal within single quote then we must use backslash (\). To specify any special character we need to use backslash, even if we want to print backslash.

In the following example we will also learn about new feature of PHP 5.0 called heredocs, in this technique we do not need to mention any single or double quote instead of that all we have to do is after echo statement start the statement with <<< followed by any string and the whole content must be ended with the same string. It facilitates us to not to bother about to print the special characters like \,",' etc. We can freely print these all.

PHP String Function Example:

<?php

$a="This is a string";

echo $a."<br/>";

var_dump($a);

echo <<<EOT

<br/> This

is another

way

of printing

"string".

EOT;

?>

Output:

This is a string
string(16) "This is a string"
This is another way of printing "string".

Advertisement

Related Tags for PHP String Function:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 15, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com