| <?php echo 'My first php script'; ?> |
The code above represents the easiest php script available. A simple command that displays 'My first php script' on viewer's browser.
To start being more confident with php, you can copy the code and paste it in a text editor, then save the file as filename.php (can be any name, of course...). Reach it typing www.yoursite.com/filename.php into your browser address bar.
Php scripting requires the following tags to work:
<?php // this is the opening tag
?> // this is the closing tag
The server will process any command within opening and closing tags as Php functions.
Php is a widely
supported by a large community of users on the net. You will easily find more complex scripts, tutorials, documentation, applications etc.
This Googlerank's Randomize for Ranking section is designed to give newbies the ability to grab our free random scripts and place them on their webpage. If you want to get a deeper knowledge of Php you can start from these websites:
![]() |
PHP Tutorials Written by Experts on Range of Topics Suitable for Beginners to Advanced Programmers |
![]()
Embedding a PHP script into a webpage is easier than including a javascript. The only difference is that your web page MUST have a *.PHP extension.
With few exceptions, all you have to do is copy a php script and paste it wherever you want into the actual html of your page . When you're done, rename your html file and give it a .php extension.
That's it.
Example.
| <?php echo 'PHP Random'; ?> |
That's our tiny little script we used above. Now we want to incorporate it into a HTML webpage.
Let's suppose we have the following simple code:
| <html> <head> <title>This is my first embedded PHP</title> </head> <body> <p><h1>Php embedding example</h1></p> <p><h3>This resource has been released by <a href="http://www.googlerank.com">Googlerank PHP Random Tools</a></p> <p><h2>If it works, I should read the words PHP Random (in red) above this line</h2></p> </body> </html> |
Now we want to embed the PHP script into the HTML code above. So just COPY it and PASTE it into the BODY (anywhere) of the page so you get the code below
<html> <?php </font> |
Notice that a <font> tag has been added before PHP script. This because we wanted to color the script's output. This is not mandatory, of course.
You can test the script by yourself, copy the code above into a text editor (Windows Block Notes is good enough at this stage, but you're advised to use a more featured text editor like UltraEdit), and then save the files as random.php.
Upload it onto your web space and reach it with your browser.
You'll see something like this
If you check out random.php source by viewing html code, you'll see no traces of php script. That's because the script has been parsed by the server and ONLY the output is displayed by the browser.
You can also embed multiple php scripts into a webpage. This method lets you run different and variable objects inside just one page.
A very basic example of this can be this:
<?php <?php <HTML><BODY> foo(); ?> |
![]()
There's another way to incorporate php scripts into a Html page. This method introduces the notion of 'INCLUDE' php command. It's used to recall external php scripts. At server level, the process is absolutely the same. Instead of having the whole script embedded into the page, you just recall it with a function (include).
The server will include and process the script as the page is viewed. This method offers effective advantages: minor file size, easy updating (you just have to edit one single php file), html code is kept clean.
'Include' command is used to recall and incorporate 'conditions', 'statements', 'files'.
Since we're not about to create complex applications, we'll explain 'include' command to recall external 'files'. That's what we need to work with php random tool on next page.
Correct include function syntax is:
| <?php include("menu.inc"); ?> |
In syntax above we have recalled the file menu.INC : Inc extension is generally used for files which are supposed to be included in other pages. Usually inc files are made of plain html code.
By the way, we'll need to incorporate external php files, so nothing changes, except for the file extension:
| <?php include("menu.php"); ?> |
Example
We have this php script, which displays current time calculated in the famous Swatch™ beats format.
<?php function swatchbeats() <?php print(swatchbeats()); ?> |
Swatchbeats script by Michael Hanney, 1999 |
We have learnt that we could copy the entire php code and paste it wherever we wish into an actual html page. But now we want to INCLUDE the script as an external file.
Copy the script above and save it as beats.php
Now we take the same old simple html page. Add the include function wherever you want swatchbeats time to appear
<html> <?php </font> |
Save this file as swatchbeats.php.
Then upload BOTH files beats.php and swatchbeats.php to your webhosting, and reach swatchbeats.php via browser.
Note: many servers require a ASCII mode when uploading scripts.
You should see something like this
We have learnt:
1. what is Php and how it works. Most of all we have learnt that this scripting language is not more difficult than javascript when we embed it in a webpage.
2. To embed a Php script into a page, just copy and paste the script wherever you want into html code. Then you have to save the file with PHP extension.
3.
A basic usage of INCLUDE function
That's nearly all you have to know to properly use our PHP Random Tools.
Googlerank Start Page | The Definitive Google Ranking Strategy Guide | Genesis Doorway Pages creator | Privacy Policy