How does php work with javascript?
i want to use php and javascript togethar in a single html document. but i dont know how to use it. Please help me out and let me know what will the proper extension used for such a file. Show asked Mar 29, 2011 at 5:05
0 First, note that :
That PHP file will generate an HTML page -- which may contain Javascript code. Once the HTML page is received by the browser, it will be displayed, and Javascript will be executed. answered Mar 29, 2011 at 5:08
Pascal MARTINPascal MARTIN 389k77 gold badges647 silver badges656 bronze badges php can't work in an html file. php only works in php files. you can add html and javascript in php files easily. answered Mar 29, 2011 at 5:09
HeadshotaHeadshota 20.5k11 gold badges59 silver badges79 bronze badges The can work together. The do not work simultanously. PHP work when the page was at server. JS work the page goes to browser. answered Mar 29, 2011 at 5:17
iamgopaliamgopal 8,3765 gold badges36 silver badges52 bronze badges
Is not fair to compare PHP vs JavaScript, as they both have different purposes for web-site development. PHP is a server-side scripting language while JavaScript is a client-side scripting language. In fact, the most dynamic website is created when we use functions of both these languages together. If PHP is like a paint-brush to paint picture, then JavaScript is a paint-color. PHP stands for “Hypertext Preprocessor”, is a programming language embedded in HTML that does all sort of things like build custom web content, send and receive cookies, evaluate form data sent from a browser, etc. It is integrated with number of popular databases like Postgre SQL, Oracle, Sybase, SQL, and MySQL. PHP also supports major protocols like IMAP, POP3 and LDAP. PHP can handle forms, save data to a file, return data to the user, gather data from files, etc. Example: Let say a website that takes user to view the order status after logging in. By PHP coding, you would send a query to the database that would then output the specific user information based on what information is in the database JavaScriptWhile, JavaScript is designed for creating network-centric applications. With JavaScript, web pages will no longer be static HTML and allows the program that interacts with the user, control the browser, and dynamically create the HTML content. The advantage of JavaScript is that it has less server interaction, allowing you to validate user input before sending the page off which means less load on your server and less server traffic. JavaScript allows immediate feedback to the visitors. Example: When you hover over the menu tab on the web-page, the drop down effect is done through JavaScript. Note: JavaScript now supports server-side execution via NodeJS Difference between Javascript vs PHPHere is the main difference between JavaScript and PHP:
PHP vs JavaScript: RepositoryHere is the main difference between PHP and JavaScript for repository:
Trend of JavaScript vs PHPJob trends from indeed.com shows millions of jobs search for Java-script and PHP from thousands of job sites. It relatively shows the growing and falling trend of the job for both languages in consecutive years. Job Trends for JavaScript Job Trends for PHP Likewise, regional interest of people for JavaScript or PHP are also highlighted over-here. In this PHP vs JS graph, though we can see the fall of interest of JavaScript versus PHP languages over the period of time due to introduction of new languages, JavaScript still remains on top of PHP. Can we use PHP with JavaScript?You can't run PHP code with Javascript. When the user recieves the page, the server will have evaluated and run all PHP code, and taken it out.
Why JavaScript is used with PHP?The greatest advantage of JavaScript over PHP lies in the fact that JavaScript is a full-stack development language. Most JS vs PHP comparisons emphasize that JavaScript is front end only, but that is simply not true. You can develop an entire web or mobile app with no other technology than JavaScript.
|