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!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment