Share on Google+Share on Google+

PHP String Function

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:


$a="This is a string";

echo $a."<br/>";


echo <<<EOT

<br/> This

is another


of printing





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


Posted on: March 15, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null