PHP: Our first PHP script

This entry is part 2 of 54 in the series PHP Tutorial

We will first look at a few PHP examples.  Here I assume that you have some understanding of HTML which is sufficed for us for now.

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>
Try The Code

Echo is similar to writeln in C.

In this example, the entire string <p>Hello World</p> will be output to the browser and this string is also what the browser will see.

And as for us, we will see Hello World in the browser when the script is ran.

PHP: The language

This entry is part 1 of 54 in the series PHP Tutorial

PHP is a popular general-purpose scripting language that is especially suited to web development.

Fast, flexible and pragmatic, PHP powers everything from your blog, as in this wordpress blog, to the most popular websites in the world.

When it comes to developing for the web, you could say PHP provides everything for us to build a complete web site.  And it does certain things really well such as in accessing the backend database.

If you have gone through the Javascript tutorial, you would find that Javascript gives a better separation between HTML and script whereas for PHP, the HTML is embedded in the script making it more difficult to learn.

If you are at this point and wanted to learn PHP, I would suggest that you also brush up on database and have some basic understanding of database tables, querying using select statements, insert and deleting records in the database table.

I will create a MySQL tutorial at a later time.

jQuery: .each()

This entry is part 32 of 33 in the series jQuery Tutorial

The .each(function()) will iterate over a jQuery object, executing a function for each matched element.

Each time the callback or function runs, it is passed the current loop iteration, beginning from 0.

More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to the element.

<!doctype html>
<html>
<head>
    <title>each demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <style>
        ul {
            font-size: 18px;
            margin: 0;
        }

        span {
            color: blue;
            text-decoration: underline;
            cursor: pointer;
        }

        .example {
            font-style: italic;
        }
    </style>
</head>
<body>

To do list: <span>(click here to change)</span>
<ul>
    <li>Eat</li>
    <li>Sleep</li>
    <li>Be merry</li>
</ul>

<script>
    $('span').click(function () {
        $('li').each(function () {
            $(this).toggleClass('example');
        });
    });
</script>

</body>
</html>

Submit Video

In this case, this is referred to the li element.

jQuery: not

This entry is part 31 of 33 in the series jQuery Tutorial

For not method, the supplied selector is tested against each element; the elements that don’t match the selector will be included in the result.

<!doctype html>
<html>
<head>
    <title>not demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <style>
        div {
            width: 50px;
            height: 50px;
            margin: 10px;
            float: left;
            background: yellow;
            border: 2px solid white;
        }

        .green {
            background: #8f8;
        }

        .gray {
            background: #ccc;
        }

        #blueone {
            background: #99f;
        }
    </style>
</head>
<body>

<div></div>
<div id='blueone'></div>
<div></div>
<div class='green'></div>
<div class='green'></div>
<div class='gray'></div>
<div></div>

<script>
    $('div').not('.green, #blueone')
            .css('border-color', 'red');
</script>

</body>
</html>

Post Your Gameplays

In this example, class=’green’ and id=’blueone’ will be excluded when applying the .css method.

jQuery: siblings

This entry is part 30 of 33 in the series jQuery Tutorial

The siblings method allows us to search through the siblings of these elements in the DOM tree and construct a new jQuery object from the matching elements.

<!doctype html>
<html>
<head>
    <title>eq demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <style>
        li {
            background: yellow;
        }

        .silver {
            background: silver;
        }
    </style>
</head>
<body>

<ul>
    <li>list item 1</li>
    <li>list item 2</li>
    <li class='third-item'>list item 3</li>
    <li>list item 4</li>
    <li>list item 5</li>
</ul>

<script>
    $('li.third-item').siblings().addClass('silver');
</script>

</body>
</html>

YOUR TEXT

Notice that list items 1, 2, 4 and 5 are selected but not list item 3.