Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

PHP and JavaScript Relation

PHP is a server-side scripting language that operates on the web server, while JavaScript is a client-side scripting language that operates in web browsers. PHP can generate JavaScript code as a string and render it to the browser. This allows JavaScript code to be written inside PHP code or outside in the same file. JavaScript can also manipulate elements on an HTML document using the DOM API from within PHP code. Both languages have their strengths - JavaScript is well-suited for client-side interactions and PHP excels at server-side tasks like communicating with databases.

Uploaded by

HANNALEI NORIEL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

PHP and JavaScript Relation

PHP is a server-side scripting language that operates on the web server, while JavaScript is a client-side scripting language that operates in web browsers. PHP can generate JavaScript code as a string and render it to the browser. This allows JavaScript code to be written inside PHP code or outside in the same file. JavaScript can also manipulate elements on an HTML document using the DOM API from within PHP code. Both languages have their strengths - JavaScript is well-suited for client-side interactions and PHP excels at server-side tasks like communicating with databases.

Uploaded by

HANNALEI NORIEL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TECHNOLOGICAL UNIVERSITY OF THE PHILIPPINES - CAVITE

Name: Hanna Lei D. Noriel Course/Yr./Section: BSIE-ICT-3A Date: 11/21/22

Leader & Members: (Individual Activity)


Subject: ICT5 Activity No: 5

Instructor: Sir Jhonnielben Apa Activity Name: PHP and Javascript

Description of the Activity: Explain how is PHP related to Javascript.


What is PHP?
According to upwork.com (2022), as a general-purpose, server-side scripting language, PHP, also
known as “Hypertext Preprocessor”, operates on the web server rather than in a web browser like
Google Chrome. It uses a recursive acronym to indicate its open-source nature, much like GNU (“GNU's
Not Unix”). Rasmus Lerdorf, a Danish-Canadian programmer, created the language’s first two iterations
and collaborated on its subsequent revisions. An interpretive language is one that the host computer
reads line by line. In contrast, compiled languages require that every single line of code be transformed
from top to bottom into machine code before any of the code can be executed.

What is JavaScript:
JavaScript was just a client-side scripting language up until 2009, which meant it could only be used in
a browser. Node.js, a server-side runtime environment that enables JavaScript to run on a web server,
has made it feasible to execute server-side JavaScript code to construct dynamic webpages, similar to
how PHP is used right now. (upwork.com, 2022)

How is PHP related to JavaScript?


As per geeksforgeeks.org (2021), PHP is a server-side scripting language, whereas JavaScript is a
client-side scripting language. JavaScript is used on the client side to inspect and validate client
information, while PHP is used on the server side to communicate with databases. HTML is utilized in
PHP code as a string. We generate JavaScript code as a string in the PHP code and render it to the
browser.

Example 1: Write JavaScript code inside of PHP code.

Code:

<?php
echo '<script type="text/JavaScript">
prompt("GeeksForGeeks");
</script>'
;
?>
Output:

Example 2: Outside of the PHP code, write JavaScript code (in same PHP file)

Code:

<?php
// some php stuff
?>
<script type="text/javascript">
alert('GeeksforGeeks!');
</script>

Output:
Example 3: Manipulation of the DOM in JavaScript (in same PHP file)

Code:

<?php
echo "<div id='demo'></div>";
?>
<script type="text/JavaScript">

// Function is called, return


// value will end up in x
var x = myFunction(11, 10);
document.getElementById("demo").innerHTML = x;

// Function returns the product of a and b


function myFunction(a, b) {
return a * b;
}
</script>

What are PHP and Javascript’s Strengths and Weaknesses?


In conclusion, JavaScript is most often used for creating web pages, but it is also utilized in a number of
other non-browser environments while PHP is a server-side programming language designed especially
for developing a website. (geeksforgeeks.org, 2021)

REFERENCES:

GeeksforGeeks. (2021, August 1). How to run JavaScript from PHP? https://www.geeksforgeeks.org/how-to-

run-javascript-from-php/

Upwork. (2022, February 1). PHP vs. JavaScript: Comparing Strengths and Weaknesses

https://www.upwork.com/resources/php-vs-javascript

You might also like