Dismounted
59.***.***.***Echo
PHP Echo The PHP function echo is a means of outputting text to the web browser. Throughout your PHP career you will be using the echo function more than any other. So let's give it a solid perusal! Outputting a String To output a string, use the PHP echo function. You can place either a string variable or you can use quotes, like we do below, to create a string that the echo function will output.PHP code:
<?php $myString = "Hello!"; echo $myString; echo "<h5>I love using PHP!</h5>"; ?>
Display:PHP code:
<?php // This won't work because of the quotes around specialH5! echo "<h5 class="specialH5">I love using PHP!</h5>"; // OK because we escaped the quotes! echo "<h5 class=\"specialH5\">I love using PHP!</h5>"; // OK because we used an apostrophe ' echo "<h5 class='specialH5'>I love using PHP!</h5>"; ?>
If you want to output a string that includes quotations, either use an apostrophe ( ' ) or escape the quotations by placing a slash in front of it ( \" ). The slash will tell PHP that you want the quotation to be used within the string and NOT to be used to end echo's string. Echoing Variables Echoing variables is very easy. The PHP developers put in some extra work to make the common task of echoing all variables nearly foolproof! No quotations are required, even if the variable does not hold a string. Below is the correct format for echoing a variable.PHP code:
<?php $my_string = "Hello Bob. My name is: "; $my_number = 4; $my_letter = a; echo $my_string; echo $my_number; echo $my_letter; ?>
Display:PHP code:
<?php $my_string = "Hello Bob. My name is: "; $newline = "<br />"; echo $my_string."Bobettta".$newline; echo "Hi, I'm Bob. Who are you? ".$my_string.$newline; echo "Hi, I'm Bob. Who are you? ".$my_string."Bobetta"; ?>
Display: