获取 "[img]XXXXX[/img]" 标签 PHP 之间的字符串



嗨,我有一个问题,我现在不知道如何在 [img] [/img] 标签之间获取字符串

例如:

$string = "Hello i am new [img]nice_photo[/img] so here is my avatar [img]avatar[/img] ok its all";

我会得到字符串"头像"和"nice_photo">

请帮忙谢谢。

编辑: 嗯,我举一个例子,什么会让我有一个字符串,例如:$s = "Hello [img] nice [img]https://imgur.com/ddd.jpg/[/img] this is a photo"

我有一系列允许的域:

$domains = array("Imgur.com", "iv.com");

我将检查 [img] [/img] 之间的域,如果标签之间的域在数组中$domains那么就可以了 如果标签之间的域不在数组中,则字符串将更改为:

$s_new = "Hello [img] nice [img]***[/img] this is a photo"

使用preg_match

$matches = [];
preg_match_all('/[img](.*?)[/img]/', $string, $matches);
// $matches[1] has all the matches

嗯,我举一个例子,什么会让 我有一个字符串,例如:$s = "Hello [img] nice [img]https://imgur.com/ddd.jpg/[/img] this is a photo"

我有一系列允许的域:

$domains = array("Imgur.com", "iv.com");

我将检查 [img] [/img] 之间的域 如果标签之间的域在数组$domains中,则为 og 如果标签之间的域不在数组中,则字符串将更改为:

$s_new = "Hello [img] nice [img]***[/img] this is a photo"

最新更新