一直不能下决心好好学习,仔细研究一下,决定用尽量降低难度曲线的方法,从易到难,一步一步的学习,所以整了个 demo 项目。
git 仓库 git clone https://github.com/lang123789/swoole_demo.git 然后设置了标签,本文对应 v1.0 cd swoole_demo git checkout v1.0 有提示错误之类,但代码已经切换到 v1.0 了。 然后需要自己配置好本地的 nginx ,这样才能用浏览器访问。
需求 1、写一个 html 静态页面,带样式,带 js 函数可以把用户输入的话显示在对话列表。
测试网址 127.0.0.1/index.html
主要代码 function my_message_html(incoming_message) { var newMessage = '
' + '
' +
'
' + '我自己' + '
';
return newMessage; }
function chatter_message_html(incoming_message) { var newMessage = '
' + '
' + '管理员' + '
' +
'
' +
'';
return newMessage; }
function update_chatWindow(incoming_message, from) { if (from === 1) { var msg_html = my_message_html(incoming_message); } else if (from === 0) { var msg_html = chatter_message_html(incoming_message); } $(".chat-window").append(msg_html); }
———————————————— https://www.wenjuan.com/s/AJz2EnS <?php
//字符串 $str = ' 11111 22222 33333- 44444-4444 ';
//正则表达式 $regular = '/\d{5}(?(?=-)-\d{4})/';
//执行匹配正则表达式 preg_match_all($regular, $str, $matches);
//打印结果 echo '
';
print_r($matches);
echo '
';
输出结果
Array ( [0] => Array ( [0] => 11111 [1] => 22222 [2] => 44444-4444 )
) \d{5} 匹配前面 5 位数字
(?(?=-)-\d{4}) 使用向前查看 ?= 来匹配一个 - 连字符,如果符合条件,那么 -\d{4} 将匹配该连字符和随后的 4 位数字。
这样一来 33333 - 就被排除了,因为它缺少后面要匹配的 4 位数字
// Singleton.php namespace Creational\Singleton; use Exception;
final class Singleton { private static ?Singleton $instance = null;
public static function getInstance(): Singleton
{
if (static::$instance === null) {
static::$instance = new static();
}
return static::$instance;
}
private function __construct()
{
}
private function __clone()
{
}
public function __wakeup()
{
throw new Exception("Cannot unserialize singleton");
}
}{ "name": "cloong/design-patterns-php", "description": "simple design patterns for php", "require": { "php": ">=7.0" }, "require-dev": { "phpunit/phpunit": "^9" }, "license": "MIT", "authors": [ { "name": "bianca.lk.alex", "email": "bianca.lk.alex@outlook.com" } ], "minimum-stability": "stable", "autoload": { "psr-4": { "Creational\\": "creational/", "Structural\\": "structural/", "Behavioral\\": "behavioral/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } } }