Thursday, February 2, 2012

PHP Tutorial : How does it work ? ( Part 2 )


When you save it on your desktop, rename it to test.php, (change the extension from. Html to. Php).
 Thus, the server php is advised that this page contains PHP code (the browser can not display in the case).

 Close your editor. Double-click directly on your page test.php: What a disappointment!

 You do not open a web page but ... the code that you just left, in a text editor which is probably notebook without syntax highlighting.
 (By the way, take the opportunity to set your computer to open notepad + + default for PHP files) ...

 This is where having installed WampServer on your machine will be helpful. Indeed, you need a
 PHP interpreter installed locally.

 Open your wamp server. Once started, click on its icon in the status bar on the right, a sort of half-yellow sphere, much as half a grapefruit.

 Choose www directory:

the graphical interface of serveur wamp


In the window that opens, create a folder PHP and slip your file test.php. You always pass the icon "grapefruit" to access your files.
 Now click on this icon, then localhost. In the window that opens, heading your project, open the PHP ...
 Click on your file test.php and see the work ... The day displayed in English, date to be always up to date ...

 Click View / Source in your browser: You can see that there is no trace of PHP, there are only HTML ...

 Here's quickly what is happening at each refresh:
 PHP server goes straight to the files that have a PHP extension, then it goes right to the PHP tags for this file, and interprets what's inside:
 Here, it displays (echo) all that is in parentheses and concatenates or glue if you want (the point)
the result of the function returns the date that day in English ...
 He therefore interpreted the PHP to translate it into HTML.
 Then it returns the file to the browser, which knows only display the HTML (or CSS) ... well that's good, he only sees the HTML now ...

 But if you come back tomorrow on this page, the date function will display another day in the HTML. Here for the technical aspect.

 For getting started with Wamp, that this does not hold for now:

Getting started with Wamp :

            1 * When you want to find your code: icon and wwwdirectory and PHP / your file ...
            2 * When you want to see the product of your work, in short, test your code: icon and localhost directory PHP and your file ...

 It will quickly become a reflex ...
 Now that everything is our first step will focus on the variables and the echo structure and meaning so that the displays are used at all times ...
 Here are some examples ... that you test by adding your file within the PHP tags of course.

 But first here is the result of what we did on my browser :


See You

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More