unknown os platform
Free Beginner PHP Tutorials - Output a string | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - Output a string


Free
2016/08/26 / Science and Tutorials

Echo command is used to output a string or a variable in PHP. See example:






In PHP, there are two basics ways to output a string.
Echo and print command.

A String in computer science is any finite sequence of characters (i.e., letters, numerals, symbols and punctuation marks). An important aspect of each string is its length,  defined as the number of characters in it.

For this tutorial, I will show how to output a string in PHP using both echo command and print command as shown below.

The PHP echo Command


<?php
    echo"What a fantastic day?";
?>


The above code will output the following.

What a fantastic day?

Besides, A string can also be outputted inlined on  HTML Tags as shown in the example below.

<?php     echo"<b>What a fantastic day?</b>"; ?>

The above code will output bolded string as shown below.

What a fantastic day? 

The PHP print Command


The print Command can be used with or without parentheses: print or print(). Check the example below.

without parentheses

<?php     print "What a fantastic day?"; ?>

with parentheses

<?php     print ("What a fantastic day?"); ?>

The above code will output the following.
What a fantastic day?













You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment