|
|
|---|
Printing Strings in PHPIn this section, we will learn to print strings. Also, see how to print values of variables along with strings, with help of some examples. Simple PrintingSimple printing in PHP means that we will assign a string to a variable and print it's value in the output. Let us begin with this simple example.
<?php In the above example, we used a backslash when we enclosed the string 'Let's Rock' in single quote. This is called escaping. This is essential when you want to avoid PHP from processing certain portion of code. For example, if you can put \ in front of variable $string in your echo statements to avoid printing the value of the variable, such as \$string. Sometimes, you may have to put more backslashes, like \\\$string Printing VariablesWe will now look at assigning a string to a variable and printing it's value as an output. See this example:
<?php You must try to experiment with the above code and modify it to see how it works. That will be a great learning experiencing for you! Let's also take a look at some built-in constructs of PHP that we can make use of to print one or more strings. SOme of these are:
These built-in constructs can be used in the same way we use 'echo' to print strings. We will now move on to our next section on String Comparison |
|
|
|---|