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
+1 -1
View File
@@ -95,7 +95,7 @@ class Test extends Command
*/ */
public function handle() public function handle()
{ {
$logFile = getLogFile("seed-points"); $logFile = format_description('[img=http://www.baidu.com][img]http://www.baidu.com[/img]');
dd($logFile); dd($logFile);
} }
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0'); 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('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+10 -1
View File
@@ -5631,9 +5631,10 @@ function format_description($description)
//匹配不同块 //匹配不同块
$attachPattern = '\[attach\].*\[\/attach\]'; $attachPattern = '\[attach\].*\[\/attach\]';
$imgPattern = '\[img\].*\[\/img\]'; $imgPattern = '\[img\].*\[\/img\]';
$imgPattern2 = '\[img=.*\]';
$urlPattern = '\[url=.*\].*\[\/url\]'; $urlPattern = '\[url=.*\].*\[\/url\]';
$quotePattern = '\[quote.*\].*\[\/quote\]'; $quotePattern = '\[quote.*\].*\[\/quote\]';
$pattern = "/($attachPattern)|($imgPattern)|($urlPattern)|($quotePattern)/isU"; $pattern = "/($attachPattern)|($imgPattern)|($imgPattern2)|($urlPattern)|($quotePattern)/isU";
// $pattern = "/($attachPattern)|($imgPattern)|($urlPattern)/isU"; // $pattern = "/($attachPattern)|($imgPattern)|($urlPattern)/isU";
$delimiter = '{{{}}}'; $delimiter = '{{{}}}';
$description = preg_replace_callback($pattern, function ($matches) use ($delimiter) { $description = preg_replace_callback($pattern, function ($matches) use ($delimiter) {
@@ -5660,6 +5661,14 @@ function format_description($description)
'url' => $matches[1] '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)) { } elseif (preg_match('/\[url=(.*)\](.*)\[\/url\]/isU', $item, $matches)) {
$results[] = [ $results[] = [
'type' => 'url', 'type' => 'url',