Difference between revisions of "PHP"

From TORI
Jump to: navigation, search
 
Line 58: Line 58:
   
 
can be used.
 
can be used.
  +
  +
Example:
  +
<poem><nomathjax>
  +
welcome.php
  +
<html>
  +
<body>
  +
  +
Welcome <?php echo $_POST["fname"]; ?>!<br>
  +
You are <?php echo $_POST["age"]; ?> years old.
  +
  +
</body>
  +
</html>
  +
  +
  +
03.html
  +
<!DOCTYPE html>
  +
<html>
  +
<body>
  +
  +
<form action="welcome.php" method="post">
  +
Name: <input type="text" name="fname">
  +
Age: <input type="text" name="age">
  +
<input type="submit">
  +
</form>
  +
  +
</body>
  +
</html>
  +
</nomathjax></poem>
   
 
As in [[Mathematica]], In PHP, types of variables have no need to be especially declared. The type of variable is assigned according to the type of expression in th eright hand side of the assignment operator.
 
As in [[Mathematica]], In PHP, types of variables have no need to be especially declared. The type of variable is assigned according to the type of expression in th eright hand side of the assignment operator.

Revision as of 17:24, 11 December 2018

PHP is programming language designed to make website and to write robots.

In the case of macintosh, PHP comes together with the XCode package. As other programs, it can be localized with command which php. Command man php characterises PHP it as follows:
is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
The same definition is suggested at the http://php.net/ site [1].

PHP coode

The PHP code begins with word $\rm <?php $

The code ends with word $\rm ?\!>$

Between these two words, the PHP commands are placed. These commands are executed in a way similar to that in other languages, while the php program or the web browser finds the code.

Wikipedia suggests [2] the following example of code embedded to HTML

<!DOCTYPE html>
<meta charset=utf-8>
<title>PHP Test</title>
<?php
echo 'Hello World';
?>

The specification of charset is not essential, but helps to deal with case, if any non–ascii characters appear in the text echoed: for some languages, even in century 21, several systems of encoding are used; a text, prepared at one computer, looks as abracadabra, while viewed at another computer. In century 20, In some countries, the mafia at the top of government blocked elaboration of the united encoding for national language in computers; this was important part of prohibition of non-authorized distribution of information [3]. The great efforts of programmers and users were required to mitigate this problem. The specification charset=utf-8 serves as reminder, that one should always use Unicode for important documents.

Executing from the command line

PHP code stored in file $a$.php can be executed from the command line with command

php $a$.php

where $a$ denotes name of file.

Variables

Names of variables begin with the $\$$ sign. In TORI, the dollar sign switches the math style for typing formulas. To load a PHP program to TORI, the options

$\rm < nomathjax >$

and

$\rm <\! poem \! >$

can be used.

Example:


welcome.php
<html>
<body>

Welcome <?php echo $_POST["fname"]; ?>!

You are <?php echo $_POST["age"]; ?> years old.

</body>
</html>


03.html
<!DOCTYPE html>
<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">
</form>

</body>
</html>

As in Mathematica, In PHP, types of variables have no need to be especially declared. The type of variable is assigned according to the type of expression in th eright hand side of the assignment operator.

Sintax

The syntax of PHP is similar to that of C++; many C++ expressions can be used in PHP as is.

However, in order to provide new line, instead of just "\n", in PHP one should type "\r\n".

References

  1. http://php.net/ What is PHP? try the introductory tutorial http://jp2.php.net/tut.php After that, check out the online manual http://php.net/docs.php
  2. https://en.wikipedia.org/wiki/PHP
  3. In the USSR, the Soviet veterans had prohibited the centralized rusification of computers; and many encodings are used for the Russian characters. Since that, English becomes more robust, than Russian. The recovery of the Russian culture after the anti-Russian activity of the Soviet veterans may take long time, if at all. Use of utf-8 is important for such a recovery.


Keywords

Programming language, C++