Date php
Welcome to the website to learn PHP programming online.
Thursday, November 26, 2015
Handling PHP types
PHP does not require (or support) explicit type definition in variable declaration; the type of the variable is determined by the context in which the variable is used. That is, if you assign a string value to variable $ var, then $ var becomes a string. If an integer value is then assigned to the same variable $ var, it becomes an integer.
An example of the automatic conversion of types of PHP is the addition operator '+'. If both operands are float, then the result will be a float. The operands will be interpreted as integers, and the result will be integer. Note that this does not imply that the types of the operands themselves change; the only change is in how the operands are evaluated and the type of expression itself.
<?php
$foo = "0"; // $foo is string (ASCII 48)
$foo += 2; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a float (3.3)
$foo = 5 + "10 Tiny piglets"; // $foo is integer (15)
$foo = 5 + "10 Little Pigs"; // $foo is integer (15)
?>
If you feel confused the last two examples above, see String conversion to numbers.
To force a variable to be evaluated as a certain type, see the section on Type casting. To change the variable type, see settype ().
To test any of the examples in this section , use the var_dump () function.
Note:
The behavior of the automatic conversion to array is currently undefined.
Also, because PHP supports indexing string through offsets using the same syntax used in array indexing, the following examples are valid for all versions of PHP:
<?php
$a = 'car'; // $a is a string
$a[0] = 'b'; // $a remains a string
echo $a; // bar
?>
Wednesday, November 25, 2015
What is PHP?
PHP is a language suitable for Web development and can be embedded into HTML very popular open source. It is popular because a large number of web pages and portals are created with PHP. Open Source means that it is free and free to all developers who want to use it . Embedded in HTML it means that the same file will be able to combine PHP code with HTML code, according to rules.
PHP is used to generate dynamic web pages. Remember we call static page that the contents remain always the same, while those called dynamic pages whose content is not always the same. For example, the content can be changed based on the changes you have in a database, search or user input, etc.
PHP How does it work? The PHP language is processed on servers, which are powerful computers with special software and hardware. When a type http://www.mysite.com/index.php address into a web browser such as Internet Explorer, Firefox or Chrome, what happens? Data request to the server which processes are sent, gathers the data (that say it is a dynamic process) and the server is returning an HTML page like static.
The scheme is: Reference website server -> The server receives the request, gathers the necessary information by consulting databases or other websites, other servers, etc -> The server responds by sending a "normal" website (static) but whose creation was dynamic (making processes so that the returned web page is not always the same).
Static Content : Reference -> Answer
Dynamic pages : Reference -> Processing and preparation -> Answer
In a dynamic site, the information is generally contained in a database. Every time we show the page, such as a News page, look in the database have the latest news that you entered to display in the visitor's browser. But how do you get to the page will show new news? Simply loading them in the database, for example, through a form that fills a person and filling once when you press "Send" means that what you have written is stored in our database. Thus, when we ask the website and server refer to the database, you will find this new information and show our differently than it looked before.
Generally this kind of language is often used to create dynamic content and interact with the user.
An example of the contents of a web page php, that we will store in a file that ends with a .php extension and containing text:
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Welcome to learn PHP";
?>
</body>
</html>
|
As you can see the contents of the file contains HTML code and at one point a <? Php means that there begins the given PHP code appears. Therefore we say that the PHP code is embedded (included or embedded) in HTML code.
Therefore the PHP pages contain HTML with PHP code in them to do "something" (in this case, display Welcome to aprenderaprogramar.com The PHP code is between special tags beginning and end. <? Php and?>
These special labels allow us to get in and out of "PHP mode". We serve the web server to know that has to interpret the code included between these tags as PHP.
What distinguishes PHP from JavaScript is that the code is executed on the server, generating HTML and send it to the client as if it were a static website. The customer will receive the results the server returns after interpreting PHP code, with no way of determining what the result code has been received. That is, through our browser we could see the HTML code, but not the PHP code that led to the HTML output. The web server can even be configured so that users can not know whether or not you are using PHP.
Best of using PHP is that it is extremely simple for the beginner, but in turn, offers many advanced features for professionals and advanced programmers.
With PHP you can process the form data, generate dynamic page content, or send and receive cookies, and much more. PHP used the web from small to large companies. Many web applications are built using PHP. We can cite Joomla and Drupal (content management of web pages), osCommerce and Prestashop (line On-for ecommerce stores), phpBB and SMF (forum systems for web pages), Moodle (learning platform for online education) etc.
PHP can also be used to present results and other data standards or own web development languages such as XHTML and any other XML files. PHP can autogenerate these files and store them on the file system instead of presenting them on the screen, using these files to generate dynamic content. That is, dynamic content can arise from sites other databases.
You can also interact with other servers using any protocol. Finally, PHP can be linked to other powerful languages like Java.
In short, PHP is a powerful, widely used and of great interest for the web development language.
PHP can also be used to present results and other data standards or own web development languages such as XHTML and any other XML files. PHP can autogenerate these files and store them on the file system instead of presenting them on the screen, using these files to generate dynamic content. That is, dynamic content can arise from sites other databases.
You can also interact with other servers using any protocol. Finally, PHP can be linked to other powerful languages like Java.
In short, PHP is a powerful, widely used and of great interest for the web development language.
Subscribe to:
Posts (Atom)