嗨,我有个问题,我现在不知道如何在[img] [/ img]标签之间获取字符串
例如:
$string = "Hello i am new [img]nice_photo[/img] so here is my avatar [img]avatar[/img] ok its all";
我将得到字符串“ avatar”和“ 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"
答案 0 :(得分:1)
使用preg_match
:
$matches = [];
preg_match_all('/\[img\](.*?)\[\/img\]/', $string, $matches);
// $matches[1] has all the matches
答案 1 :(得分:0)
嗯,我举个例子
我有一个字符串,例如:$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"