How To Make A Script

Table of contents:

How To Make A Script
How To Make A Script

Video: How To Make A Script

Video: How To Make A Script
Video: How to Write a Short Script 2024, May
Anonim

Literally translated, the word script means "script", that is, a description of the sequence of actions that need to be performed in order to complete a specific task. With regard to Internet programming, such tasks can be, for example, displaying a clock on an Internet page, implementing various visual effects with pictures, etc. And the display in the browser of the page itself on the modern network is also performed according to the script specified in the script. Let's try to write a couple of simple scripts to get an idea of what they are.

How scripts are written
How scripts are written

Instructions

Step 1

Depending on where the script is executed, scripts are divided into "client" and "server". Going to some address on the network, we send the URL of the page of interest to the server, and that server runs the script (script) located at the specified address. The script, performing the actions programmed in it on the server, collects the page from the necessary blocks and sends it to the browser. This is a server-side script. Having received the page, the browser on our computer renders it for us, and if there is a script in the received page code, then it is already executing this script. This is a client script.

For a server or browser to read, understand and execute a script, it must be written and written according to the rules they know. Such sets of rules are called scripting languages. Most server side scripts are currently written in PHP, and most client side scripts are written in JavaScript. To write a script yourself, it is enough to have an ordinary text editor - notepad. But for constant programming of scripts, you cannot do without a specialized editor. Such an editor takes over the lion's share of the routine work of writing scripts, leaving the programmer more time for creativity.

Let's write a simple script in the server-side PHP language. The first line is to tell the performer that the script starts from this point. In PHP, this opening tag looks like this: Between these two tags are instructions - language operators. For example, the instruction to print the inscription left by O. Bender on the Caucasian rocks is written like this: echo ("Kisya and Osia were here"); And the instruction to show the current time in the format HOUR: MINUTE is written like this: echo date ('H: i'); A complete PHP script composed of these statements will look like this: <? Phpecho ("B");

echo date ('H: i');

echo ("Kisya and Osya were here!");?> After executing this script by the server executor program (language interpreter), the page would look like this:

Server script execution result
Server script execution result

Step 2

And the same script in client-side JavaScript would look like this: var now = new date ();

document.write ("B");

document.write (now.getHours () + ":" + now.getMinutes ());

document.write ("Kisya and Osya were here!"); Here the line var now = new date () instructs the script executor to create a new virtual object named "now", which represents the current date and time. document.write () is a command to write in the page what is indicated in parentheses, and the now.getHours () and now.getMinutes () commands instruct to extract the current hour and minute from the “now” object.

It remains for greater clarity to combine these two scripts into one file, save it on the server and type the URL in the address bar of the browser. As a result, we will see the same lines, one of which was executed according to our script on the server (PHP interpreter), and the other on our computer (JavaScript interpreter).

Recommended: