< Language Tutorials(Redirected from Language Tutorials/PHP/Basic Syntax)

SandCastleIcon.png This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet, as we cannot guarantee the safety of other websites.
Document stub.png This article is a stub. It may be incomplete, unfinished, or have missing parts/sections. If the article can be expanded, please do so! There may be suggestions on its talk page. (August 2018)

PHP, which originally stood for Personal Home Page but is now a recursive acronym for "PHP: Hypertext Preprocessor",[1] is for dynamically generating webpage content, which is HTML by default. The Server runs the PHP code, then sends the output to the browser.

PHP Tags

The <?php and ?> tags in PHP are used to define the start and end of PHP scripts. Text outside of these tags are regular HTML. These tags can go anywhere, and they can be used more than once. For example:

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <?php
            //PHP code goes here
        ?>
    </body>
</html>

Syntax

Like many other programming languages, commands in PHP must be separated using semicolons (;).

A comment in Scratch.

Like Scratch, comments can be used to explain code. The text in a comment is not interpreted as code, so it is not run. In PHP, comments can either be defined by using two slashes (//), which makes the rest of the line a comment, with a hash (#), which also makes the rest of the line a comment, or with /* and */. Text within /* and */ become a comment. In PHP, comments can also be used to temporarily disable code by putting /* and */ around it.

Outputting Text

In Scratch, text can be shown with say [] and say [] for () secs. In PHP, text is outputted using echo and print. The two are mostly similar, except echo is slightly faster, and print returns (reports) true when it runs successfully. It is best to use echo in most cases. Here is how it's used:

echo "hello";

or

print "hello";

References

Cookies help us deliver our services. By using our services, you agree to our use of cookies.