0

I am new to php, html and javaScript.. I still do not understand the connection between the three. SO this may sound silly.

I know that php is a server side language. But that fact is not very clear to me since we can use php code inside html..

So my question is if i wrote the following, where does the part runs on?? does that piece of code is sent to the client browser and execute it at client side? or execute on the server side and upload the result to the client side?

<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";
?>

</body>
</html>
0

5 Answers 5

4

It is run on the server, the output html is sent to the client, and your browser displays it.

Sign up to request clarification or add additional context in comments.

Comments

2

As you already pointed out, PHP is executed on the server since the browser doesn't understand PHP at all.

If a user/browser requests your index.php file, the server executes all the PHP-Statements in your PHP-File.

So your PHP Script will generate the following code:

<!DOCTYPE html>
<html>
<body>


My first PHP script!


</body>
</html>

This is the generated HTML-code from your PHP file which is then sent back to the browser.

Hope this solves your question :)

Comments

1

in simple words it's a three tier, first your PHP code runs on server, gets interpreted to HTML, then sent to the browser on your device, which in turn 'the browser' runs the Javascript code (if it is there) and then displays the page accordingly

Comments

1

What happens on the server:

echo "My first PHP script!";

What happens at the client browser

My first PHP Script

Also, any javascript will the executed at the client side. For example:

alert("Hi")

Will be read by the browser and generate a pop-up with "Hi".

Enjoy the ride!

Here is are good resources to learn:

Comments

0

Little basic thing from my side.

If your file have .php extension then you can write HTML,PHP,JavaScript/j Query Script in that file.

But if your file have .html extension then you can write only and only HTML script and JavaScript/j Query in that file.

PHP : Server side executable language.

HTML/Java/JQuery : Client Side executable Script.

test.php

    <!DOCTYPE html>
    <html>
<head>
<script>
//js code
</script>
</head>

    <body>

    <?php
     echo "Write here php code";
    ?>

    My first PHP script!


    </body>
    </html>

test.html

<!DOCTYPE html>
<html>

<head>
<script>
//js code
</script>
</head>
<body>

You can't write PHP code in this file, can only write HTML and Javascript/jquery.
My first PHP script!

</body>
</html>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.