PHP vs HTML

AusQB

New Member
Can someone explain to me clearly what the main advantage(s) of using PHP over regular HTML are?

Does it depend of the style/content of the site or it it just a more functional language?


Also, what is a typical use for PHP?
 

cmjvulavala

New Member
PHP isnt to be used instead of HTML... its to be used with HTML.

HTML is basically what you are using to setup your page layout, add text to the site, add images to your site.

PHP is used to make your site interactive... and this usually involves outputing some HTML to the users browser to provide feedback (eg. you make a form using HTML, you process the completed form using PHP and then output feedback again using HTML)

If you want to know more about either PHP or HTML check out http://www.w3schools.com
 

conor

New Member
I completely agree. HTML cannot really be compared with PHP because they are both used for doing different things. If you want a static website use HTML. If you want a dynamic website use HTML/JavaScipt/PHP
 

adx

New Member
Also, what is a typical use for PHP?

Anything that looks automated. Both the time stamp on your post and your post count is done with PHP. Those kinds of things would take too much time to do manually and would take up too much manpower.
 

AusQB

New Member
That all makes sense, thanks.


Rather than create a new thread, I'll just ask this here:

How do I make it so that my nav buttons invoke the include() function to replace the content of a static area?
 

cmjvulavala

New Member
I dont quite understand why you are trying to do? Are you wanting to have a button that you can click and it puts some text into a textbox on your webpage. If so then thats best done with Javascript anyway rather than PHP as you wont need to refresh the page if you use javascript :)
 

AusQB

New Member
I dont quite understand why you are trying to do? Are you wanting to have a button that you can click and it puts some text into a textbox on your webpage. If so then thats best done with Javascript anyway rather than PHP as you wont need to refresh the page if you use javascript :)

Yeah I can see that, thanks.

In that case, do you mind starting me off with the basic outline of the script I need?
 

cmjvulavala

New Member
Use the onclick HTML attribute to call a javascript function
<input type="button" onclick="changetext()">

Then add the javascript to the body of your document
function changetext() {
// Code to change the textbox
}


You can lookup the code to change the stuff in the textbox cause its easy enough to find using Google and if I did thata for you then you wouldnt learn anything :p
 

AusQB

New Member
I'm having a lot of trouble trying to import large chunks of code from external files, so I'm trying PHP again.

Is there a similar statement to "document.getElementById()" in PHP? I want to be able to specify where to include() a file.
 

conor

New Member
Is there a similar statement to "document.getElementById()" in PHP? I want to be able to specify where to include() a file.

You have two understand the difference between PHP and JavaScript.

Javascript is a client side language, ie. it operates on your browser after the page has loaded and allows you to change stuff on the page without needing to reload.

PHP is a server side language which executes on the server and then sends, in most cases, a static HTML page to the person who requested it. All changes made with PHP on a page do require a reload to take effect.

Therefore if you want to include a different page on each load in PHP then you could pass the information on what page is to be loaded through a querystring (the piece after the question mark in the URL). You could try something like this:

Code:
<?php

    /* determine the pagename passed through the URL */

    if(isset($_GET['pagename'])) $pagename = $_GET['pagename'];
    else $pagename = 'home';

    /* load a different include depending on the page selected */

    switch ($pagename) {
        case 'home':
            include 'home.php';
        break;
        case 'about':
            include 'about.php';
        break;
        case 'contact':
            include 'contact.php';
        break;
    }

    /* display navigation links with querystring attatched */

    echo '
    <ul>
        <li><a href="index.php?pagename=home">Home</a></li>
        <li><a href="index.php?pagename=about">About</a></li>
        <li><a href="index.php?pagename=contact">Contact</a></li>
    </ul>
    ';

Hope That Helps
 

Fandy

New Member
I think compare the both HTML and PHP in not so sensible thing because both are use for website developing but HTML used for static website Making and for the dynamic site we use HTML/Java/PHP
 
Top