The difference between php and js: 1. js is a script language that works on the browser side, while php is a script that works on the server side; 2. The data submitted by js is handed over to the browser for processing, while php The data is submitted to the server for processing, and the server responds to the browser.
Recommended: "PHP Video Tutorial"
The difference between php and js
The syntax is similar. What you said above is correct. js=javascript is a scripting language that works on the browser side. The data it submits is handed over to the browser for processing. But the current Ajax technology can already deliver the data submitted by js to the browser for processing.
php is a script that works on the server side. It submits data to the server for processing, and the server responds to the browser. You have to look at the BS structure for this. Suggestions for learning: Many people learn js first, which is correct, but if you learn PHP first, js is learned with needs, and what you learn will be more targeted.
Recommended: "javascript Advanced Tutorial"
Embedding page method
JS embedding method:<script>< /script></script>
PHP embedding method:
##Javascript output
1.alert("Warning content")
2.prompt("Prompt content")3.document.write ()(Page output content)
PHP output
1.echo (commonly used)//Can output multiple strings at the same time eg: echo $a,"hello "; 2.print //Only one string can be output eg: print $a;3.print_r();//An array can be printed
4. var_dump();//The content, type and length of the output variableData type
JS data type
Integer (integer) int
Single precision decimal floatDouble precision decimal double
Decimal decimal Boolean bool (can only store two states ) Datetime type datetime Character char (not commonly used) strong String string (not commonly used) strongPHP data type
bool Boolean type (storing two states)int type integer type
float(double) floating point typechar character string string string
Define variables
JS defines variables: var a = 10;
2. If you define a string variable, the value after the equal sign needs to be enclosed in double quotes or single quotes)
PHP defines variables: $a = 5; $a = "hello"; $ a = ## 2. If you define a string variable, the value after the equal sign needs to be enclosed in double quotes or single quotes) String splicingJS characters String concatenation: " "; eg: "hello" "world"
String concatenation in PHP: "."; eg: "hello"."world"
Special to PHP Variable characteristics// Escape characters: generally used in strings to output special content
// \" Output double quotes \t Tab character \n Newline eg:$s = "wo\"rld"; //Escape and quote $s = "wo\trld"; //Escape tab $s = "wo\nrld"; //Transfer Line break$a = "Hello";
//Parse variables $b = "hello{$a}"; //Output hello, hello
Type conversion
Type conversion in JS
1. Convert to integer: parseInt();
3. Determine whether it is a legal numeric type: isNaN();
Type conversion in PHP
1.$a = ( Int)$a; //Force variable a to be an integer
2.$b = settype($b,"string"); //Force variable a to be a string
$s = 5;
1.var_dump(empty($s)); //empty($s) determines the variable s Whether it is empty, it can be 0, an empty string, or undefined
2.unset($s); //Delete variable s
3.var_dump(isset( $s)); //isset($s) determines whether variable s is defined Special usage in PHP 1. Variable address $a = "hello"; $b = &$a; //& represents the address of the variable echo($b); //The output result is hello 2. Variable variable $s = "hi"; $hi = "Hello"; echo $$s; //The output is hello The right tool does the right thing. Using awesome tools does not mean that a person becomes awesome. There is a ceiling in every field. The browser is the home of JS, but the server is not the home of JS. Unlike the browser, the server can only run JS. JS runs on the server The environment (Node) is very different from the browser. On the server, the Node application is run as an independent daemon process. A slight mistake in the code may cause the process to crash and exit, and modifying the code requires restarting the Node process to take effect (those automation tools nodemon /pm2 essentially restarts the service). The server's PHP is more like a browser, both providing a relatively stable container to execute scripts. Therefore, a PHP virtual host environment can stably run multiple PHP sites. It is difficult for you to write PHP code that crashes in PHP containers (such as PHP-FPM and Apache). Browsers will also try to avoid crashes caused by website JS problems. For example, browsers Chrome/Firefox and PHP-FPM both use multi-process architecture. Sub The crash of the process will not affect the main process. The main process can restart a child process to provide services. Look at the gone ASP, JSP that even Java developers don't love, the lonely RoR, and the ever-changing If you are interested in Python Web, you will know that Node, which is now constantly promoting the full stack, will be one of them sooner or later. Google doesn’t like JS and wants to promote its own Dart, but it fails. Microsoft doesn’t like it. JS, I want to promote my own TypeScript. Facebook is not very satisfied with JS, so React created its own JSX. It can be seen that not everyone is satisfied with JS on the browser side, let alone the Node solution of porting V8 to the server. If I want to say which language has seriously threatened the PHP market, I would say that language is ASP. But fortunately, in order to deal with JavaEE, Microsoft gave up ASP and created ASP.NET, which is similar to Java Web. ASP cannot be cross-platform and is not open source, so it naturally loses in the competition with PHP. .Because PHP implements pragmatism and mass line thinking, PHP without the support of wealthy families can still dominate the Internet. The success of PHP lies in unswervingly following the mass line. Quantitative changes (number of users/ The amount of code) causes qualitative changes. The amount of users is reflected in the fact that more than 82% of websites on the Internet use PHP drivers. The amount of code is reflected in the various function extensions that come with PHP and the various blogs/forums/mall systems developed using PHP. Only a language that is more PHP than PHP can possibly replace PHP. "More" is reflected in being simpler, more practical, more efficient, and with lower learning/development/operation and maintenance costs than PHP. I am very happy to see this. The language has come out, but obviously, it’s not there yet.
The above is the detailed content of What is the difference between php and js. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
