diff --git a/blog/php-basic/function.md b/blog/php-basic/function.md index 0bba9bdcd22c7db2ff99cffbce5db19799556f4e..70ee8bbb3a3aa22fd5a135c8c59d0e9dbe2e2b95 100644 --- a/blog/php-basic/function.md +++ b/blog/php-basic/function.md @@ -182,7 +182,7 @@ echo $hello; 1、作用域分类: -- 超全局变量:系统定义的变量(预定义变量:$\_POST) +- 超全局变量:系统定义的变量(预定义变量:`$_POST`) - 没有访问限制 - 全局变量:函数外部定义的变量 - 只允许在全局空间中使用,理论上函数内部不可用 diff --git a/blog/php-basic/include.md b/blog/php-basic/include.md index 6e0bbe52026cfa10b830ff99e58844d872fd0537..8decfc52c434ec67d33c11b72a7b4d3e6355af39 100644 --- a/blog/php-basic/include.md +++ b/blog/php-basic/include.md @@ -1,4 +1,4 @@ -# PHP 文件包含 +# PHP 文件包含include/require 在一个 PHP 脚本中,去将另一个文件包含进来 @@ -19,7 +19,7 @@ 语法 -``` +```php include '文件路径'; include('文件路径'); ``` diff --git a/blog/php-basic/index.md b/blog/php-basic/index.md index 390745db5256183881d08ea4244c56ad118ea47d..d60de13c5c33c4b5ef8d735ca28cc88c17333025 100644 --- a/blog/php-basic/index.md +++ b/blog/php-basic/index.md @@ -16,9 +16,9 @@ 7. [PHP 常用的系统函数](blog/php-basic/system.md) -[PHP 文件包含](blog/php-basic/include.md) +8. [PHP 文件包含include/require](blog/php-basic/include.md) -[PHP 函数 function](blog/php-basic/function.md) +9. [PHP 函数 function](blog/php-basic/function.md) [PHP 错误处理 error](blog/php-basic/error.md) diff --git a/blog/websocket/index.html b/blog/websocket/index.html new file mode 100644 index 0000000000000000000000000000000000000000..f902573d9931f0d44e49a4b7edd3951bd472f35e --- /dev/null +++ b/blog/websocket/index.html @@ -0,0 +1,39 @@ + + + + + + + + + WebSocket Demo + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/blog/websocket/package.json b/blog/websocket/package.json new file mode 100644 index 0000000000000000000000000000000000000000..a771409883efa3433ea716a40d665339f23db41b --- /dev/null +++ b/blog/websocket/package.json @@ -0,0 +1,19 @@ +{ + "name": "websocket", + "version": "1.0.0", + "description": "", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "dayjs": "^1.11.1", + "express": "^4.17.3", + "nodejs-websocket": "^1.7.2", + "socket.io": "^4.4.1" + } +} diff --git a/blog/websocket/server.js b/blog/websocket/server.js new file mode 100644 index 0000000000000000000000000000000000000000..c4c7b74b9834f8782f5607892f315b8ba866633c --- /dev/null +++ b/blog/websocket/server.js @@ -0,0 +1,21 @@ +const { Server } = require('socket.io'); +const { createServer } = require('http'); + +const httpServer = createServer(); + +// 处理跨域 +const io = new Server(httpServer, { + cors: { + origin: '*', + }, +}); + +io.on('connection', (socket) => { + // 接收数据 + socket.on('message', (data) => { + // 发送数据 + socket.emit('message', data); + }); +}); + +httpServer.listen(8080);