PHP_Part2.pptx - PHP:HypertextPreprocess or Part 2 1 Mr...

This preview shows page 1 - 7 out of 26 pages.

PHP: Hypertext Preprocess or Part 2 Mr. Shahid Waseem (UoSA) 1
Image of page 1

Subscribe to view the full document.

PHP 5 echo and print Statements Mr. Shahid Waseem (UoSA) 2 In PHP there is two basic ways to get output: echo and print. In the PHP we use echo (and print) in almost every example. So, this topic contains a little more info about those two output statements.
Image of page 2
PHP echo and print Statements Mr. Shahid Waseem (UoSA) 3 There are some differences between echo and print: echo - can output one or more strings print - can only output one string, and returns always 1 Tip: echo is marginally faster compared to print as echo does not return any value.
Image of page 3

Subscribe to view the full document.

The PHP echo Statement Mr. Shahid Waseem (UoSA) 4 echo is a language construct, and can be used with or without parentheses: echo or echo(). The next example shows how to display different strings with the echo command (also notice that the strings can contain HTML markup):
Image of page 4
PHP Source: PHP Source: Output Results Output Results Mr. Shahid Waseem (UoSA) <html> <body> <?php echo "<h2>PHP is fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP! <br>"; echo "This", " string", " was", " made", " with multiple parameters."; ?> </body> </html> PHP is fun! Hello world! I'm about to learn PHP! This string was made with multiple parameters. 5 PHP echo Statement (Display Strings)
Image of page 5

Subscribe to view the full document.

PHP Source: PHP Source: Output Result: Output Result: Mr. Shahid Waseem (UoSA) <html> <body> <?php $txt1="Learn PHP"; $txt2="W3Schools.com"; $cars=array("Volvo","BMW","Toyota") ; echo $txt1; echo "<br>"; echo "Study PHP at $txt2"; echo "<br>"; echo "My car is a {$cars[0]}"; ?> </body> </html> Learn PHP Study PHP at W3Schools.com My car is a Volvo 6 PHP echo Statement(Display Variables)
Image of page 6
PHP Source PHP Source Output Results Output Results Mr. Shahid Waseem (UoSA) <html> <body> <?php print "<h2>PHP is fun!</h2>"; print "Hello world!<br>"; print "I'm about to learn PHP!"; ?> </body> </html> PHP is fun!
Image of page 7
You've reached the end of this preview.
  • Summer '17
  • mubassar

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern