format_description() support another img bbcode syntax

This commit is contained in:
xiaomlove
2023-03-26 23:42:17 +08:00
parent c28d2c5e23
commit 9e41eef12e
3 changed files with 12 additions and 3 deletions

View File

@@ -95,7 +95,7 @@ class Test extends Command
*/
public function handle()
{
$logFile = getLogFile("seed-points");
$logFile = format_description('[img=http://www.baidu.com][img]http://www.baidu.com[/img]');
dd($logFile);
}

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-19');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-26');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -5631,9 +5631,10 @@ function format_description($description)
//匹配不同块
$attachPattern = '\[attach\].*\[\/attach\]';
$imgPattern = '\[img\].*\[\/img\]';
$imgPattern2 = '\[img=.*\]';
$urlPattern = '\[url=.*\].*\[\/url\]';
$quotePattern = '\[quote.*\].*\[\/quote\]';
$pattern = "/($attachPattern)|($imgPattern)|($urlPattern)|($quotePattern)/isU";
$pattern = "/($attachPattern)|($imgPattern)|($imgPattern2)|($urlPattern)|($quotePattern)/isU";
// $pattern = "/($attachPattern)|($imgPattern)|($urlPattern)/isU";
$delimiter = '{{{}}}';
$description = preg_replace_callback($pattern, function ($matches) use ($delimiter) {
@@ -5660,6 +5661,14 @@ function format_description($description)
'url' => $matches[1]
]
];
} elseif (preg_match('/\[img=(.*)\]/isU', $item, $matches)) {
//是否图片
$results[] = [
'type' => 'image',
'data' => [
'url' => $matches[1]
]
];
} elseif (preg_match('/\[url=(.*)\](.*)\[\/url\]/isU', $item, $matches)) {
$results[] = [
'type' => 'url',